hdu 4632区间 dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4632
用点容斥原理转移状态,
dp[i][j]=dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1]
当 s[i] == s[j], 要加上 dp[i+1][j-1] + 1;
我就是想的太复杂,而这个题有卡时间,无限TLE,悲剧啊!
- #include <cstdio>
- #include <cmath>
- #include <algorithm>
- #include <iostream>
- #include <cstring>
- #include <queue>
- #include <vector>
- #define maxn 1050
- #define INF 0x3f3f3f
- using namespace std;
- const int moder = ;
- int dp[maxn][maxn];
- char s[maxn];
- int n;
- int main()
- {
- //if(freopen("input.txt","r",stdin)== NULL) {printf("Error\n"); exit(0);}
- int T;
- cin>>T;
- for(int t=;t<=T;t++){
- scanf("%s",s);
- n = strlen(s);
- for(int i=;i<n;i++) dp[i][i] = ;
- for(int i=;i<n;i++) dp[i][i-] = ;
- for(int i=n-;i>=;i--)
- for(int j=i+;j<n;j++){
- dp[i][j] = dp[i][j-] + dp[i+][j] - dp[i+][j-];
- if(s[i] == s[j]) dp[i][j] += dp[i+][j-] + ;
- dp[i][j] = (dp[i][j] + moder) % moder; //没加moder,wa了好几次;
- }
- printf("Case %d: %d\n",t,dp[][n-]);
- }
- }
hdu 4632区间 dp的更多相关文章
- HDU 4632 区间DP 取模
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4632 注意到任意一个回文子序列收尾两个字符一定是相同的,于是可以区间dp,用dp[i][j]表示原字 ...
- hdu 4632(区间dp)
Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65535 K (Java/ ...
- hdu 4632区间dp 回文字串计数问题
Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65535 K (Java/ ...
- hdu 4283 区间dp
You Are the One Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化
HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化 n个节点n-1条线性边,炸掉M条边也就是分为m+1个区间 问你各个区间的总策略值最少的炸法 就题目本身而言,中规中矩的 ...
- HDU 4293---Groups(区间DP)
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=4293 Problem Description After the regional con ...
- String painter HDU - 2476 -区间DP
HDU - 2476 思路:分解问题,先考虑从一个空串染色成 B串的最小花费 ,区间DP可以解决这个问题 具体的就是,当 str [ l ] = = str [ r ]时 dp [ L ] [ R ] ...
- 2016 ACM/ICPC Asia Regional Shenyang Online 1009/HDU 5900 区间dp
QSC and Master Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- HDU 4570(区间dp)
E - Multi-bit Trie Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
随机推荐
- treeview右键添加新节点
private void advTree1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Righ ...
- ios第三方工具
1. DXPopover 带尖叫的提示框 2. MMDrawerController 最好的抽屉效果 3.MMProgressHUD 提示框 4.Reachability :网络链接检测 UIBu ...
- C#操作求出SQL中某一字段所有行的和方法!
DataTable table = xx.sqlcha(sql1);//调数据库 ; foreach(DataRow row in table.Rows)//遍历所查出记录所有行 { v = v + ...
- webpack学习笔记一(入门)
webpack集成了模块加载和打包等功能 ,这两年在前端领域越来越受欢迎.平时一般是用requirejs.seajs作为模块加载用,用grunt/gulp作为前端构建.webpack作为模块化加载兼容 ...
- Visual Studio vs2010 去掉中文注释红色下划线;去掉代码红色下划线;
vs去掉下挂线也分两种: 1.去掉中文注释红色下划线,需要去掉VisualAssist下划线鸡肋功能: 1.选择Visual AssistX Options: 2.把如图所示的勾去掉,解决. 以后再次 ...
- Spring 整合Redis 出现 afterPropertiesSet signature: ()V) Incompatible argument to function 解决办法
正在做SpringMVC+Redis整合的练习 使用的是 spring-data-redis 和 Jedis 配置好之后出现了以下错误: Caused by: java.lang.VerifyErro ...
- dede取得指定栏目的链接
获取标签 typeid 为目录的 id {dede:type typeid='1'} <a href="[field:typelink /]">[field ...
- SQL Server 连接字符串和身份验证
SQL Server .NET Data Provider 连接字符串包含一个由一些属性名/值对组成的集合.每一个属性/值对都由分号隔开. PropertyName1=Value1;P ...
- Python 基础-python函数
函数 1.def 2.命名 3.函数体 4.return 返回值 def get_return(): a = 1 return a 函数参数有 形参和实参 定义几个形参就 ...
- 《C和指针》章节后编程练习解答参考——6.2
<C和指针>——6.2 题目: 编写一个函数,删除源字符串中含有的子字符串部分. 函数原型: int del_substr(char *str, char const *substr); ...