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) 编辑