| ||||||||||
| 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 | |||||||||
dp都超时了 郁闷~~~#include <iostream>
using namespace std;
char str[5000];
short cost[3][5000];
int mincost(int i,int j)
{
if(i==1||i==0)
return 0;
else
{
if(str[j]==str[j+i-1])
return cost[(i+1)%3][j+1];
else
{
int k1=cost[(i+2)%3][j]+1;
int k2=cost[(i+2)%3][j+1]+1;
return (k1>k2?k2:k1);
}
}
}
void main()
{
int N;
scanf("%d %s",&N,str);
int i,j;
for(i=0;i<=N;i++)
for(j=0;j<=N-i;j++)
{
cost[i%3][j]=mincost(i,j);
}
printf("%d",cost[N%3][0]);
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator