HDOJ 4745 (区间DP)
来源:互联网 发布:java注册登录代码 编辑:程序博客网 时间:2024/06/06 05:13
the problem is here
this is a very typical range dp question ,and I made some comment right after the code down here ,the main stream of the quiz is find the longest Palindrome sub-sequence in range of [i,j],and the find the maximum of them.
#include <bits/stdc++.h>#include <cstring>#define ll long long#define maxn 1005using namespace std;int s[maxn],dp[maxn][maxn];int main(){ int n; while(cin>>n) { if(!n) break; memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++) { cin>>s[i]; dp[i][i] = 1; } for(int i=1;i<=n-1;i++) //length? { for(int j = 1;i+j<=n;j++) //start point? { int k = i+j; // end point? dp[j][k] = max(dp[j][k],max(dp[j+1][k],dp[j][k-1])); if(s[k] == s[j]) { dp[j][k] = max(dp[j][k],dp[j+1][k-1]+2); //2 represent the length of the two matched number } } } int ans =0; for(int i=1;i<=n;i++) { ans = max(ans,dp[1][i]+dp[i+1][n]); } cout<<ans<<endl; } return 0;}
阅读全文
0 0
- HDOJ 4745 (区间DP)
- HDOJ 5115 Dire Wolf(区间DP)
- hdoj Dire Wolf 5115 (区间DP) 好题
- HDOJ 5115 Dire Wolf 区间DP
- hdoj 5115 Dire Wolf 【区间dp 暴力】
- hdoj 2476 String painter 【区间dp】
- hdoj Jam's maze 5617 (区间DP&&滚动数组)好题
- HDU 4745 Two Rabbits(区间DP)
- HDU 4745 Two Rabbits (区间DP)
- hdu4597(区间dp)
- poj1651 (区间dp)
- hdu4283(区间DP)
- poj2955(区间DP)
- poj1141(区间DP)
- hdu2476(区间DP)
- poj1651(区间DP)
- lightoj1422(区间DP)
- zoj3469(区间DP)
- Kaggle 流程
- C++结构体类型解惑
- input之key(一)
- 单例模式
- 前端知识
- HDOJ 4745 (区间DP)
- ubuntu16.04安装teamviewer和飞鸽传书
- STL中pair的用法
- UNP(卷2:进程间通信)—— 第一章:简介
- 图灵机的意义与思想内涵
- css中的IFC
- PHP的输出缓冲区
- idea用maven构建java+scala项目
- Java实现-将二叉树拆成链表