| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
贴个简单的滚动数组。。。#include <iostream>
#include <cstdlib>
#include <algorithm>
#define N 5010
#define REP(i,n) for(i=0;i<n;i++)
using namespace std;
int main()
{
int i,j,k,n;
cin>>n;
char a[N],b[N];
scanf("%s",a);
REP(i,n) b[i] = a[i];
reverse(a,a+n);
short dp[2][N];
REP(i,n)
{
dp[0][i] = 0;
dp[1][i] = 0;
}
REP(i,n)
{
REP(j,n)
{
if( a[i] == b[j] )
dp[(i+1)%2][j+1] = dp[i%2][j]+1;
else
{
dp[(i+1)%2][j+1] = dp[i%2][j+1];
if( dp[(i+1)%2][j+1] < dp[(i+1)%2][j] )
dp[(i+1)%2][j+1] = dp[(i+1)%2][j];
}
}
}
cout<<n-dp[n%2][n]<<endl;
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator