随笔分类 -  DP中的状态转移

摘要:View Code //找活动结束时间最小的,即以活动结束时间进行排序#include<iostream>#include<algorithm>using namespace std;int t ,k;struct node{ int a,b; }s[101];int cmp( node x, node y ){ if(x.b==y.b) return x.a<y.a; return x.b<y.b;} int main(){ int i,j; while( cin>>t , t ) { for( i = 0 ; i < t ; i++ ) 阅读全文
posted @ 2011-06-01 17:09 聊聊IT那些事 阅读(325) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3787View Code #include"iostream"using namespace std;int main(){ char a[1001],b[1001]; int c[1001],d[1001]; int i; while(cin>>a>>b) { int L1=strlen(a); int L2=strlen(b); int start_a=1 , start_b=1; int s=0,t=0; for(i=0;i<L1;i++) if(a[i 阅读全文
posted @ 2011-05-08 21:22 聊聊IT那些事 阅读(303) 评论(0) 推荐(0)
摘要:好久没写总结了,问题积累了不少,把做过的题型分类总结一下了,下面这些题型也是我在hdu acm step里面碰到的类型题,重新梳理一下思路。题型一:http://acm.hdu.edu.cn/showproblem.php?pid=1003hdu1003思路前段时间已经叙述过了,在这里重点说一下这种题型的入手点,一看这种题型就是属于求最大子序列的和,切入点就是找到start和end,即起始位置以及结束位置。起初,我碰到这道题的时候,也是借鉴网上的一些办法,不过随着学习的不断深入,也逐渐有了点头绪,其实思路还是和网上的基本一致,但这只是借鉴和学习,并没有真正做到融会贯通,这还需要时间吧。希望在. 阅读全文
posted @ 2011-05-04 20:55 聊聊IT那些事 阅读(456) 评论(1) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1160dp问题:状态转移——>:a[i]=a[j]+1;b[i]=j; //记录找到最下降序列的路径, 即下标标号思路:先按照重量递增排序,如果w相等,则按照速度v的递减顺序排序,最后找出以速度为关键字的递减最大子序列即可。代码如下:View Code #include<iostream>#include<algorithm>using namespace std;int b[1001];int a[1001];int c[1001];struct node{ int w; in 阅读全文
posted @ 2011-05-03 16:45 聊聊IT那些事 阅读(473) 评论(1) 推荐(0)
摘要:http://acm.fzu.edu.cn/problem.php?pid=2024View Code #include<stdio.h>#include<string.h>#define M 1010int c[M][M];int f[M][M];int min(int a,int b,int c){ int z=(a<b)?a:b; if(z<c)return z; else return c;}int Max(int a ,int b){return a>b?a:b;}void LCS(char aa[], char bb[], int x, i 阅读全文
posted @ 2011-05-02 09:15 聊聊IT那些事 阅读(226) 评论(0) 推荐(0)
摘要:View Code //Problem 2013 A short problem /*Accept: 158 Submit: 452Time Limit: 1000 mSec Memory Limit : 32768 KB Problem DescriptionThe description of this problem is very short. Now give you a string(length N), and ask you the max sum of the substring which the length can't small than M.InputThe 阅读全文
posted @ 2011-04-21 14:59 聊聊IT那些事 阅读(238) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1257导弹拦截#include"iostream"#define M 50000using namespace std;int n;int a[M];int i,j;int used[M];int flag=0;int main(){ while(cin>>n) { for(i=0;i<n;i++) cin>>a[i]; memset(used, 0 ,sizeof(used)); flag=0; for(i=0; i<n; i++) { if(used 阅读全文
posted @ 2011-03-25 18:54 聊聊IT那些事 阅读(180) 评论(0) 推荐(0)
摘要:带路径的数塔#include"iostream"using namespace std;int main(){ int a[100][100],b[100]; int i,j; int n; while(cin>>n) { for(i=0;i<n;i++) for(j=0;j<=i;j++) cin>>a[i][j]; int t=0; int y=a[0][0]; for(i=n-2;i>=0;i--) { int max=0,k=0; for(j=0;j<=i;j++) { if(a[i+1][j]>a[i+1][j 阅读全文
posted @ 2011-03-25 18:53 聊聊IT那些事 阅读(372) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1087View Code //dp问题:// 状态转移方程 b[i]=max(b[i], b[j]+a[i]);#include"iostream"using namespace std;#define M 1010int n;int a[M],b[M];int i,j;int main(){ while(cin>>n,n) { int Max=-0xffff; memset(b,0,sizeof(0)); for(i=0;i<n;i++) cin>>a[i] 阅读全文
posted @ 2011-03-23 09:08 聊聊IT那些事 阅读(539) 评论(0) 推荐(0)