上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 57 下一页

2011年8月22日

多重背包之六

摘要: #include<iostream> //poj 2392 Space Elevator #include<algorithm>using namespace std;int dp[50000];struct node{ int h,a,c; bool operator<(const node& o) { return a<o.a; }}ans[405];int k;int main(){ cin>>k; for(int i=0;i<k;++i) cin>>ans[i].h>>ans[i].a>> 阅读全文

posted @ 2011-08-22 12:23 sysu_mjc 阅读(120) 评论(0) 推荐(0) 编辑

多重背包之三

摘要: #include<iostream> //POJ 1276 Cash Machine,参照poj 1742 Coins 1040K 16MS using namespace std;int cash,n,ni[15],di[15],b[100005][2]; //b的定义参照poj 1742int main(){ while(cin>>cash>>n) { for(int i=1;i<=n;++i) cin>>ni[i]>>di[i]; if(cash==0||n==0) { ... 阅读全文

posted @ 2011-08-22 12:22 sysu_mjc 阅读(111) 评论(0) 推荐(0) 编辑

多重背包之四

摘要: #include<iostream> //poj 1742 Coinsusing namespace std;int v[105],c[105],b[100005][2]; int main(){ int n,m,i,j,count,num; while(scanf("%d%d",&n,&m),n&&m) { memset(b,0,sizeof(b)); for(i=1;i<=n;i++) scanf("%d",&v[i]); for(i=1;i<=n;i++) ... 阅读全文

posted @ 2011-08-22 12:22 sysu_mjc 阅读(90) 评论(0) 推荐(0) 编辑

多重背包之二

摘要: #include<iostream> //多重背包,POJ 1276 Cash Machine 652K 47MS using namespace std;int cash,n,ni[15],di[15],dp[100005];int main(){ while(cin>>cash>>n) { for(int i=1;i<=n;++i) cin>>ni[i]>>di[i]; if(cash==0||n==0) { cout<<"0\n";continue; ... 阅读全文

posted @ 2011-08-22 12:21 sysu_mjc 阅读(114) 评论(0) 推荐(0) 编辑

堆排序

摘要: #include<iostream> //小顶堆using namespace std;int list[100];void heappass(int list[],int i,int m) //i是根结点的编号,m是以i根结点的子树的最后一个结点编号,调整这棵子树为堆{ int j=2*i,x=list[i]; while(j<=m) //这里j==m的情况(只有一个左孩子)也应考虑进去 { if(j<m&&list[j]>list[j+1]) //若有两个孩子结点,则要list[j]是其中的较小... 阅读全文

posted @ 2011-08-22 12:20 sysu_mjc 阅读(99) 评论(0) 推荐(0) 编辑

多重背包之一

摘要: //sicily 1077. Cash Machine#include<iostream> //多重背包#include<cstring>using namespace std;int cash,n,num[20],d[20],dp[100010];int main(){ while(cin>>cash>>n) { for(int i=0;i<n;++i) cin>>num[i]>>d[i]; if(cash==0||n==0) { cout<<"0\n"; c... 阅读全文

posted @ 2011-08-22 12:20 sysu_mjc 阅读(148) 评论(0) 推荐(0) 编辑

KMP算法之四

摘要: #include <iostream> //poj 2752 Seek the Name, Seek the Fameusing namespace std;char A[500000];int m,P[500000],res[500000];void get_next(){ P[1]=0; int j=0; for(int i=2;i<=m;++i) { while(j>0&&A[j+1]!=A[i]) j=P[j]; if(A[j+1]==A[i]) j=j+1; ... 阅读全文

posted @ 2011-08-22 12:19 sysu_mjc 阅读(169) 评论(0) 推荐(0) 编辑

KMP算法之二

摘要: //sicily5 1282. Computer Game#include <iostream> //KMP算法#include<stdio.h>using namespace std;int A[1000000],B[80000]; //A是主串,B是子串,查询B串在A串的哪些地方出现int n,m,next[80000]; //n,m分别是A,B的串长度,A,B的下标是从1开始的void get_next(){ next[1]=0; int j=0; for(int i=2;i<=m;++i) { while(j>0&... 阅读全文

posted @ 2011-08-22 12:18 sysu_mjc 阅读(124) 评论(0) 推荐(0) 编辑

KMP算法之三

摘要: //poj 2406 Power Strings #include <iostream> //KMP算法using namespace std;char B[2000000]; int m,next[2000000]; void get_next(){ next[1]=0; int j=0; for(int i=2;i<=m;++i) { while(j>0&&B[j+1]!=B[i]) j=next[j]; if(B[j+1]==B[i]) j=j+1; ... 阅读全文

posted @ 2011-08-22 12:18 sysu_mjc 阅读(168) 评论(0) 推荐(0) 编辑

KMP算法之一

摘要: #include <iostream> //KMP算法是一种改进的字符串匹配算法,复杂度为O(n)using namespace std;char A[500000],B[500000]; //A是主串,B是子串,查询B串在A串的哪些地方出现int n,m,next[500000]; //n,m分别是A,B的串长度,注意A,B的下标是从1开始的void get_next(){ next[1]=0; int j=0; for(int i=2;i<=m;++i) { while(j>0&&B[j+1]!=B[i]) ... 阅读全文

posted @ 2011-08-22 12:17 sysu_mjc 阅读(153) 评论(0) 推荐(0) 编辑

上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 57 下一页

导航