上一页 1 ··· 20 21 22 23 24 25 26 27 28 ··· 47 下一页

2012年7月26日

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1849Nim博弈View Code #include <iostream>using namespace std ;int main(){ int n ; while(scanf("%d",&n),n) { int a ; int ans=0 ; while(n--) { scanf("%d",&a) ; ans^=a ; } if(!ans) ... 阅读全文
posted @ 2012-07-26 14:29 LegendaryAC 阅读(159) 评论(0) 推荐(0) 编辑
 
摘要: View Code void ZeroOnePack(int c,int w){ for(int i=V;i>=c;i--) dp[i]=max(dp[i],dp[i-c]+w) ; return ;}void CompletePack(int c,int w){ for(int i=c;i<=V;i++) dp[i]=max(dp[i],dp[i-c]+w) ; return ;}void MultiplePack(int c,int w,int a){ if(c*a>=V) { CompletePack(c,w)... 阅读全文
posted @ 2012-07-26 11:06 LegendaryAC 阅读(128) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2191裸多重背包View Code #include <iostream>#include <algorithm>using namespace std ;int dp[10001] ;int c[101],w[101],num[101] ;int V ;bool cmp(int a,int b){ return a>b ;}void ZeroOnePack(int c,int w){ for(int i=V;i>=c;i--) dp[i]=max(dp[i],dp[i-c 阅读全文
posted @ 2012-07-26 11:05 LegendaryAC 阅读(232) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1171多重背包,学自背包九讲。re一次,dp数组开多大算起来太纠结,尽可能开大就不会有事了wa一次,dp数组没有memset。。。View Code #include <iostream>using namespace std ;int dp[1000001] ;int v[51],num[101] ;int V ;void ZeroOnePack(int c,int w){ for(int i=V;i>=c;i--) dp[i]=max(dp[i],dp[i-c]+w) ; ret... 阅读全文
posted @ 2012-07-26 10:44 LegendaryAC 阅读(141) 评论(0) 推荐(0) 编辑

2012年7月23日

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2577大小写打字,注意shift的使用,注意初始化View Code #include <iostream>using namespace std ;int dp[101][3] ;int main(){ int t ; scanf("%d",&t) ; while(t--) { char s[101] ; scanf("%s",s+1) ; int len=strlen(s+1) ; memset(dp,0,sizeof(dp)... 阅读全文
posted @ 2012-07-23 22:03 LegendaryAC 阅读(124) 评论(0) 推荐(0) 编辑
 
摘要: http://poj.org/problem?id=1949一句话破题,“Farmer John's list of chores is nicely ordered, and chore K (K > 1) can have only chores 1,.K-1 as prerequisites.”View Code #include <iostream>using namespace std ;int dp[10001] ;int main(){ int n ; while(~scanf("%d",&n)) { int w,k,maxx 阅读全文
posted @ 2012-07-23 22:01 LegendaryAC 阅读(170) 评论(0) 推荐(0) 编辑
 
摘要: http://poj.org/problem?id=3230dp[i][j]表示第i天在城市j取得的最大价值这题要注意初始化,最大价值可能是负的。View Code #include <iostream>using namespace std ;int cost[101][101],income[101][101] ;int dp[101][101] ;int main(){ int n,m ; while(scanf("%d%d",&n,&m),n||m) { for(int i=1;i<=n;i++) for(int j=1;j< 阅读全文
posted @ 2012-07-23 17:19 LegendaryAC 阅读(107) 评论(0) 推荐(0) 编辑
 
摘要: http://poj.org/problem?id=1088dp的方法实在卡的不会做。。。搜索搞了View Code #include <iostream>using namespace std ;int map[101][101],dp[101][101] ;int r,c ;int dfs(int x,int y){ int tab[4][2]={1,0,-1,0,0,1,0,-1} ; if(dp[x][y]) return dp[x][y] ; int maxx=0 ; for(int i=0;i<4;i++) { int xx... 阅读全文
posted @ 2012-07-23 15:57 LegendaryAC 阅读(127) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1159dp[i][j]代表长度为i的串s1与长度为j的串s2的最长公共子串View Code #include <iostream>using namespace std ;int dp[1001][1001] ;int main(){ char s1[1001],s2[1001] ; while(~scanf("%s%s",s1,s2)) { int len1=strlen(s1) ; int len2=strlen(s2) ; memset(dp... 阅读全文
posted @ 2012-07-23 15:09 LegendaryAC 阅读(110) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1421因为考虑到差的平方最小,所以先把物品按重量排序(这样可以使相邻的两个数更加接近从而取得更优的结果)。dp[i][j]表示i件物品拿j对时最低的疲劳度i等于2*j时,dp[i][j]=dp[i-2][j-1]+(w[i]-w[i-1])^2其他情况时(即i大于2*j),dp[i][j]=min(dp[i-1][j],dp[i-2][j-1]+(w[i]-w[i-1])^2)View Code #include <iostream>#include <algorithm>using 阅读全文
posted @ 2012-07-23 09:43 LegendaryAC 阅读(418) 评论(0) 推荐(0) 编辑
上一页 1 ··· 20 21 22 23 24 25 26 27 28 ··· 47 下一页