随笔分类 -  DP

 
HDU 1231 最大连续子序列
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1231最大连续子序列,水View Code #include <stdio.h>#include <stdlib.h>int cmp(const void*a,const void*b){ return *(int*)b-*(int*)a;}int a[110000];int main(){ int n,i; int max,now; int start,end; int temp; int p,q; while(scanf("%d",&n),n) { .. 阅读全文
posted @ 2012-04-21 20:17 LegendaryAC 阅读(172) 评论(0) 推荐(0)
HDU 2571 命运
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2571dp。wa两次,设边从1开始,所以和0有关的除了ans[1][0]和ans[0][1]外都要初始化为无穷(不让从外面进来)View Code #include <stdio.h>int map[30][1100];int ans[30][1100];#define INF -100000000int max(int a,int b){ return a>b?a:b;}int main(){ int n,m; int t; int i,j,k; scanf("%d", 阅读全文
posted @ 2012-04-21 20:05 LegendaryAC 阅读(165) 评论(0) 推荐(0)
AHU 501 送钱活动
摘要:http://icpc.ahu.edu.cn/OJ/Problem.aspx?id=501和hdu1024一模一样,随便改改就过了。。。ps:安徽大学oj这个经验值系统真好玩、、View Code #include <stdio.h>#include <string.h>#include <stdlib.h>#define INF -100000000int max(int a,int b){ return a>b?a:b;}int a[1100000],p[1100000],q[1100000],now[1100000],pro[1100000];/ 阅读全文
posted @ 2012-04-21 00:13 LegendaryAC 阅读(218) 评论(0) 推荐(0)
HDU 1024 Max Sum Plus Plus
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1024求m个子段的最大和。思路见代码注释。View Code #include <stdio.h>#include <string.h>#include <stdlib.h>#define INF -100000000int max(int a,int b){ return a>b?a:b;}int a[1100000],now[1100000],pro[1100000];//now记录当前最大值,pro记录前一个的最大值 int main(){ int n,m,i, 阅读全文
posted @ 2012-04-21 00:05 LegendaryAC 阅读(216) 评论(0) 推荐(0)
HDU 4223 Dynamic Programming?
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4223View Code #include <stdio.h>#include <stdlib.h>#include <string.h>#define INF 100000000int cmp(const void*a,const void*b){ return *(int*)a-*(int*)b;}int a[110000],s[110000];int main(){ int t,n; int i; int min; int nCase=1; scanf("% 阅读全文
posted @ 2012-04-16 21:46 LegendaryAC 阅读(194) 评论(0) 推荐(0)
HDU 1003 Max Sum
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1003靠,总算过了,不解释View Code #include <stdio.h>#include <stdlib.h>int a[110000];int main(){ int t,n; int i,f; int max,now; int start,end; int temp; int nCase=1; scanf("%d",&t); f=0; while(t--) { scanf("%d",&n); scanf(" 阅读全文
posted @ 2012-04-16 18:47 LegendaryAC 阅读(144) 评论(0) 推荐(0)
HDU 1248 寒冰王座
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1248我乱搞的,标准做法01背包View Code #include <stdio.h>int test(int n){ if(n<150)return n; if(n>200&&n<300)return n-200; return n%50;}int main(){ int t,n; scanf("%d",&t); while(t--) { scanf("%d",&n); printf("%d\n 阅读全文
posted @ 2012-04-11 23:49 LegendaryAC 阅读(194) 评论(0) 推荐(0)
HDU 1284 钱币兑换问题
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1284dp,转移方程自行yyView Code #include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>int dp[10][40000]; int main(){ int n; dp[0][0]=1; for(int i=1;i<4;i++) for(int j=0;j<32768;j++) dp[i][j]=dp[i-1][j]+dp[i][j-i]; wh 阅读全文
posted @ 2012-04-08 17:43 LegendaryAC 阅读(146) 评论(0) 推荐(0)
HDU 2602 Bone Collector
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2602吾近来又开始翻阅背包九讲,确是神作,又有所感,故水01背包一道祭天。View Code #include <stdio.h>#include <string.h>int main(){ int T,N,V; int i,j; int f[1100],c[1100],w[1100]; scanf("%d",&T); while(T--) { scanf("%d%d",&N,&V); memset(f,0,sizeof( 阅读全文
posted @ 2012-02-28 13:16 LegendaryAC 阅读(162) 评论(0) 推荐(0)
HDU 2067 小兔的棋盘
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2067这道题的状态我很久以前就分析过了,是一道递推题,当初感觉思维很乱没写出来。今天好好研究了一下动态规划,发现用动态规划中记忆化搜索的思想能解决此问题。View Code #include <stdio.h>#include <string.h>int n,flag=1; __int64 d[100][100]; __int64 f(int i,int j) { if(d[i][j]>=1)return d[i][j]; if(j==1)return d[i][j]=i; if 阅读全文
posted @ 2011-12-27 21:52 LegendaryAC 阅读(211) 评论(0) 推荐(0)