随笔分类 -  动态规划(DP)

摘要:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2062&cid=1157法一:用dp[i][0]、dp[i][1]表示递推到第i位时为0以及非0的情况种数进行dp。View Code #include<stdio.h>int main(){ long long dp[20][2] ; int n, k ; while(scanf("%d %d", &n, &k)!=EOF) { dp[1][1] = k-1 ; dp[1][0] = 0 ; for(int i=2; i<=n.. 阅读全文
posted @ 2013-04-14 15:24 yelan@yelan 阅读(249) 评论(0) 推荐(0)
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=36310MS:View Code 1 #include<stdio.h> 2 #include<algorithm> 3 using namespace std ; 4 int a[31] ; 5 int n, m, ans ; 6 void dfs(int i, int v) 7 { 8 if(ans==m) 9 return ;10 if(v>m)11 return ;12 if(i<1)13 {14 ... 阅读全文
posted @ 2013-03-31 21:31 yelan@yelan 阅读(280) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1087View Code 1 #include<stdio.h> 2 #include<math.h> 3 int a[1100], dp[1100] ; 4 int main() 5 { 6 int n, i, j, max , m ; 7 while(scanf("%d", &n),n!=0) 8 { 9 for(i=0; i<n; i++)10 scanf("%d", &a[i]) ;11 dp[0] = 0 ;12 阅读全文
posted @ 2013-01-30 20:00 yelan@yelan 阅读(118) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1159View Code 1 #include<iostream> 2 #include<cstring> 3 using namespace std ; 4 char str1[10000] ; 5 char str2[10000] ; 6 int c[10000][10000] ; 7 int main() 8 { 9 int len1, len2, i, j ;10 while(cin>>str1>>str2)11 {12 len1 = strlen(st 阅读全文
posted @ 2013-01-30 19:57 yelan@yelan 阅读(164) 评论(0) 推荐(0)
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1299View Code 1 #include<stdio.h> 2 #include<string.h> 3 #define Max 1000 4 int b[Max+10] ; 5 int maxlen[Max+10] ; 6 int main() 7 { 8 int m, n, i, j ; 9 scanf("%d", &n) ;10 for(i=1; i<=n; i++)11 s 阅读全文
posted @ 2013-01-30 19:48 yelan@yelan 阅读(123) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2084View Code 1 #include<stdio.h> 2 int main() 3 { 4 int C, n, i, j ; 5 int a[110][110], dp[110][110] ; 6 scanf("%d", &C) ; 7 while(C--) 8 { 9 scanf("%d", &n) ;10 for(i=1; i<=n; i++)11 for(j=1; j<=i; j++)12 ... 阅读全文
posted @ 2013-01-30 19:45 yelan@yelan 阅读(157) 评论(0) 推荐(0)