博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVA 11552 Fewest Flops(区间dp)
阅读量:4501 次
发布时间:2019-06-08

本文共 967 字,大约阅读时间需要 3 分钟。

一个区间一个区间的考虑,当前区间的决策只和上一次的末尾有关,考虑转移的时候先统计当前区间出现过的字母以及种数ct

枚举上一个区间的末尾标号j,规定小于INF为合法状态,确定j之后看j有没有在当前的区间出现,如果出现则贪心选块数+ct-1,

枚举当前的结尾。为了方便处理,增加一个0区间,初始为0,这样所有的块数会减1,转移完以后在加上1。

#include
using namespace std;const int LEN = 1e3+3;int dp[LEN][26];char s[LEN];const int INF = 0x3f3f3f3f;//#define LOCALint main(){#ifdef LOCAL freopen("in.txt","r",stdin);#endif int T; cin>>T; //for(int i = 1; i < 26; i++) dp[0][i] = 1; //memset(dp[0],0x3f,sizeof(dp[0])); while(T--){ int k; scanf("%d%s",&k,s); int len = strlen(s), mi = len/k; for(int i = 1; i <= mi; i++){ bool exs[26] = {}; for(int j = (i-1)*k; j < i*k; j++){ exs[s[j]-'a'] = true; } int ct = 0; for(int j = 0; j < 26; j++) ct += exs[j]; memset(dp[i],0x3f,sizeof(dp[i])); for(int j = 0; j < 26; j++){ if(dp[i-1][j]

 

转载于:https://www.cnblogs.com/jerryRey/p/4850537.html

你可能感兴趣的文章
使用 https://git.io 缩短 a GitHub.com URL.
查看>>
拷贝、浅拷贝、深拷贝解答
查看>>
NS3 实验脚本的编写步骤
查看>>
四元数
查看>>
【Linux】Linux查看程序端口占用情况
查看>>
微软职位内部推荐-Software Development Engineer
查看>>
Git常用命令
查看>>
Windows 2003+IIS6+PHP5.4.10配置PHP支持空间的方法(转)
查看>>
去除express.js 3.5中报connect.multipart() will be removed in connect 3.0的警告(转)
查看>>
Android WIFI 无缝切换 小结(1)
查看>>
BZOJ 5194--[Usaco2018 Feb]Snow Boots(STL)
查看>>
BS系统开发历程
查看>>
asp.net 设置回车的默认按钮 (转载)
查看>>
Palindrome Partitioning
查看>>
Microservice架构模式简介
查看>>
换种形式工作
查看>>
javascript中三种典型情况下this的含义
查看>>
Python学习笔记day2(python基础一)
查看>>
【QC】安装
查看>>
628. Maximum Product of Three Numbers
查看>>