hdu 1513(dp+滚动数组)
2013-09-11 10:32
148 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1513
思路:n这么大,可以采用滚动数组,然后就是求原串和反串的LCS了。
View Code
思路:n这么大,可以采用滚动数组,然后就是求原串和反串的LCS了。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int dp[2][5555]; char str1[5555],str2[5555]; int n; int main() { while(~scanf("%d",&n)){ scanf("%s",str1); strcpy(str2,str1); reverse(str2,str2+n); memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(str1[i-1]==str2[j-1]){ dp[i%2][j]=dp[(i-1)%2][j-1]+1; }else dp[i%2][j]=max(dp[i%2][j-1],dp[(i-1)%2][j]); } } printf("%d\n",n-dp[n%2] ); } return 0; }
View Code
相关文章推荐
- HDU 1513 Palindrome(dp最大公共子序列+滚动数组)
- hdu 1513 && 1159 poj Palindrome (dp, 滚动数组, LCS)
- hdu 1513(dp+滚动数组)
- HDU 1024(DP+滚动数组)
- HDU 4427 Math Magic【DP+滚动数组】
- HDU 1024 Max Sum Plus Plus【DP+滚动数组】
- hdu1513 Palindrome(LCS+滚动数组)
- hdu--1176---dp && 滚动数组优化<porker>
- hdu 1024 Max Sum Plus Plus(滚动数组)(DP)
- hdu 1513 滚动数组优化 回文串
- HDU 1513 Palindrome【LCS+滚动数组】
- hdu 1513(滚动数组)
- HDU - 2294 Pendant (DP滚动数组降维+矩阵快速幂)
- HDU-1024-DP-(滚动数组优化与状态转移)
- HDU-1513 Palindrome LCS+滚动数组
- HDU 1024 Max Sum Plus Plus(DP+滚动数组)
- HDU 6199(DP)补题+一个超级有用的滚动数组思想
- hdu 3392 利用滚动数组优化的dp
- HDU 3392 Pie(dp滚动数组+思路)
- hdu 4576(概率dp+滚动数组)