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 |
Re:动态规划代码如下,注意用short,否则超内存In Reply To:动态规划代码如下,注意用short,否则超内存 Posted by:JustName at 2011-08-11 18:09:56 > #include <iostream> > using namespace std; > #include <string.h> > #define N 5001 > int n; > char s[N]; > short f[N][N]; > int solv(char s[N],int i,int j) > { > if(f[i][j]) > return f[i][j]; > if(i >= j) > return f[i][j] = 0; > if(s[i] == s[j]) > return f[i][j] = solv(s,i+1,j-1); > if(solv(s,i,j-1) < solv(s,i+1,j)) > return f[i][j] = solv(s,i,j-1) + 1; > return f[i][j] = solv(s,i+1,j) + 1; > } > int main(void) > { > scanf("%d",&n); > scanf("%s",s); > memset(f,0,sizeof(f)); > printf("%d\n",solv(s,0,strlen(s)-1)); > return 0; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator