LightOJ 1033 - Generating Palindromes(dp)
2015-11-10 13:00
309 查看
题目链接:LightOJ 1033 - Generating Palindromes
代码
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 105; int N, dp[maxn][maxn]; char s[maxn], t[maxn]; int solve () { memset(dp, 0, sizeof(dp)); for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) if (s[i] == t[j]) dp[i][j] = dp[i-1][j-1] + 1; else dp[i][j] = max(dp[i-1][j], dp[i][j-1]); } return dp ; } int main () { int cas; scanf("%d", &cas); for (int kcas = 1; kcas <= cas; kcas++) { scanf("%s", s + 1); N = strlen(s + 1); for (int i = 1; i <= N; i++) t[i] = s[N-i+1]; printf("Case %d: %d\n", kcas, N - solve()); } return 0; }
相关文章推荐
- GDI+ 使用指南(basic guiding of GDI plus )
- 小马哥----高仿小米4 tc01刷机拆机主板图与开机界面图 分联通版与移动版
- This version of the rendering library is more recent than your version of ADT plug-in. Please update ADT plug-in
- LightOJ 1032 - Fast Bit Calculations(dp)
- 深入浅出LSTM神经网络 ------从卷积 递归网络 到长短时间记忆模型
- C++基础::自制异常定位器
- 自定义控件--自定义内容可以滚动的TextView
- 面向对象设计原则之接口隔离原则
- LightOJ 1031 - Easy Game(概率)
- 把钱投资自己头脑上(三)
- 用MVP架构开发Android应用
- 黑马程序员_自定义异常
- LightOJ 1030 - Discovering Gold(dp)
- ZigBee相关资源
- 老程序员应该记住的 5 件事
- 面向对象设计原则之开闭原则
- 黑马程序员_继承
- PHP编码规范
- 深圳地铁规划图2
- 大数据大家学