摘要: 题目链接经典DP问题。由于最初if(c[i][j]>=0) return c[i][j];一句中少写一个等于号造成TLE,查了好久啊……View Code 1 #include <stdio.h> 2 #include <string.h> 3 #define MAX(a,b) ((a)>(b)?(a):(b)) 4 #define N 300 5 char a[N],b[N]; 6 int c[N][N]; 7 int f(int i,int j) 8 { 9 if(i<0 || j<0) return 0;10 if(c[i][j]>= 阅读全文
posted @ 2012-04-06 21:33 BeatLJ 阅读(302) 评论(0) 推荐(0) 编辑
摘要: 题目链接简单DP题。View Code 1 #include <stdio.h> 2 #define N 45 3 int c[N][2]; 4 int main() 5 { 6 int t,i,n; 7 c[1][0]=c[1][1]=1; 8 for(i=2;i<N;i++) 9 {10 c[i][0]=c[i-1][0]+c[i-1][1];11 c[i][1]=c[i-1][0];12 }13 scanf("%d",&t);14 for(i=1;i<=t;i++)15 {16 ... 阅读全文
posted @ 2012-04-06 17:39 BeatLJ 阅读(210) 评论(0) 推荐(0) 编辑
摘要: 题目链接简单动态规划题。View Code 1 #include <stdio.h> 2 #include <string.h> 3 #define N 500002 4 #define MAX 10000000 5 char vis[MAX]; 6 int c[N]; 7 int main() 8 { 9 int n,i,tmp; 10 c[0]=0,vis[0]=1; 11 for(i=1; i<N; i++) 12 { 13 tmp=c[i-1]-i; 14 if(tmp>0&&!vis[tmp]) vis[tmp]=1,c[i]=tm 阅读全文
posted @ 2012-04-06 17:22 BeatLJ 阅读(337) 评论(0) 推荐(0) 编辑
摘要: 题目链接简单的动态规划题,WA了4次居然是因为N太小,为自己的吝啬感到无语。View Code 1 #include <stdio.h> 2 #define N 21 3 int f[N][N][N]; 4 int w(int a,int b,int c) 5 { 6 if(a<=0 || b<=0 || c<=0) return 1; 7 if(a>20 || b>20 || c>20) return w(20,20,20); 8 if(f[a][b][c]>0) return f[a][b][c]; 9 if(a<b&&a 阅读全文
posted @ 2012-04-06 17:02 BeatLJ 阅读(213) 评论(0) 推荐(0) 编辑
摘要: 题目链接经典的动态规划题(数塔)。View Code 1 #include <stdio.h> 2 #define MAX(a,b) ((a)>(b)?(a):(b)) 3 #define N 100 4 int a[N][N],f[N]; 5 int main() 6 { 7 int n,i,j; 8 while(scanf("%d",&n)!=EOF) 9 {10 for(i=0;i<n-1;i++)11 {12 for(j=0;j<i+1;j++) scanf("%d",&a[i][j]);13 ... 阅读全文
posted @ 2012-04-06 16:11 BeatLJ 阅读(197) 评论(0) 推荐(0) 编辑