随笔分类 -  DP算法

不大量思考,绝对不可能学好动态规划这一信息学奥赛中最精致的部分。
摘要:View Code //从反面考虑:就是一个offer都没获得,最后结果p=1-p;#include"iostream"#include"algorithm"using namespace std;struct offer{ int a; double b;}s[10000];int cmp(offer x, offer y){ return x.b>y.b;}int main(){ int n,m; int i; while(cin>>n>>m,n+m) { for(i=0;i<m;i++) scanf(" 阅读全文
posted @ 2011-04-22 19:42 聊聊IT那些事 阅读(1301) 评论(1) 推荐(1)
摘要:View Code #include"iostream"using namespace std;int main(){ int n; int a[10001]; int i; int j=0; while(cin>>n,n) { memset(a,0,sizeof(a)); int start=0,end=0; int k=0; int sum=0,Max=0; int count=0; int L=20000; for(i=0;i<n;i++) { cin>>a[i]; if(a[i]<0) count++; if(a[i]==0&am 阅读全文
posted @ 2011-04-14 18:59 聊聊IT那些事 阅读(457) 评论(0) 推荐(0)
摘要:lcs#include"iostream"using namespace std;int c[1001][1001];int Max(int a, int b){ return a>b?a:b;}void LCS(char aa[], char bb[], int x, int y){ int i,j; for(i=0;i<=x;i++) c[i][0]=0; for(j=0;j<=y;j++) c[0][j]=0; for(i=1;i<=x;i++) { for(j=1;j<=y;j++) { if(aa[i-1]==bb[j-1]) {c[ 阅读全文
posted @ 2011-04-12 18:16 聊聊IT那些事 阅读(262) 评论(2) 推荐(0)
摘要:View Code #include"iostream"using namespace std;int main(){ int t; int n,a; int i,j=0,k; cin>>t; while(t--) { cin>>n; int sum=0,Max=-99999999; int start=0,end=0; k=0; for(i=0;i<n;i++) { cin>>a; sum+=a; if(sum>Max) { Max=sum; start=k+1; end=i+1; } if(sum<0) { sum= 阅读全文
posted @ 2011-04-12 14:20 聊聊IT那些事 阅读(318) 评论(0) 推荐(0)
摘要:1 #include"iostream" 2 #define M 50000 3 using namespace std; 4 int n; 5 int a[M]; 6 int i,j; 7 int used[M]; 8 int flag=0; 9 int main()10 {11 while(cin>>n)12 {13 for(i=0;i<n;i++)14 cin>>a[i];15 memset(used, 0 ,sizeof(used));16 flag=0;17 for(i=0; i<n; i++)18 {19 if(used[i] 阅读全文
posted @ 2011-03-23 18:45 聊聊IT那些事 阅读(345) 评论(0) 推荐(0)
摘要:View Code 1 #include"iostream" 2 using namespace std; 3 int main() 4 { 5 int a,b,c; 6 int sum; 7 while(cin>>a>>b>>c,a+b+c) 8 { 9 if(a==0) sum=1;10 if(b==0&&a) 11 {12 if(c==0) sum=a+1;13 else if(c)14 {15 if(a<4) sum=a+1;16 else sum=a+5*c+1;17 }18 }19 if(a*b& 阅读全文
posted @ 2011-03-23 10:02 聊聊IT那些事 阅读(294) 评论(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)
摘要:向牛人看起!http://acm.hdu.edu.cn/showproblem.php?pid=1042摘自:http://www.cnblogs.com/phinecos/archive/2009/10/06/1578411.html 阅读全文
posted @ 2010-11-16 18:50 聊聊IT那些事 阅读(1192) 评论(0) 推荐(0)
摘要:动态规划 阅读全文
posted @ 2010-10-12 16:37 聊聊IT那些事 阅读(1204) 评论(0) 推荐(0)
摘要:首次接触了一些有关dp算法的题型,开始还有点思路,但在编程的过程当中遇到了些障碍,经过一番辛苦搜索,最后,总算是把最优子序列的算法给想明白了。int maxSubSum4( const vectorint & a ){int maxSum = 0, thisSum = 0;for( int j = 0; j a.size( ); j++ ){thisSum += a[ j ];//求一段子序列的和if( thisSum maxSum )//验证该段子序列是否是所求的最大和,即最大和非负或者为最大负数maxSum = thisSum;else if( thisSum 0 )thi 阅读全文
posted @ 2010-10-10 11:43 聊聊IT那些事 阅读(1633) 评论(0) 推荐(0)