上一页 1 ··· 22 23 24 25 26 27 28 29 30 ··· 42 下一页
此类背包典型的关系是若想选b,你必须先选a,从而产生了一层依赖关系,然后给你一定限量的总钱数,让你买最大价值的东西就让我们从hdu 3449 来搞定这类最简单的依赖背包吧有很多个箱子,想买箱子中的物品必须先买下箱子,典型的依赖背包dp[i][j]代表前i个箱子花费j的钱能获得的最大价值,则可以想到每次在对一个箱子进行dp更新状态时都应该利用前面的结果来更新以前做那道金明的预算方案时,就是没有利用上层的结果来更新才一直错,dp的本质都被我给忽略了,囧!View Code #include<cstdio>#include<cstring>int dp[60][100010] Read More
posted @ 2011-11-26 14:11 Because Of You Views(1743) Comments(0) Diggs(0) Edit
输入有点繁琐View Code #include<stdio.h>#include<string.h>#include<stdlib.h>struct node { struct node *child[26]; char *str;}*root;void insert(char *c1,char *c2){ int len=strlen(c2); struct node *cur,*newnode; cur=root; for(int i=0;i<len;i++) { if(cur->child[c2[i]-'a']!=0) . Read More
posted @ 2011-11-25 16:04 Because Of You Views(262) Comments(0) Diggs(0) Edit
又是神奇的建图题,这道题充分体现了2-sat选了谁必须选谁的性质某一轮如果选了必输的方法,则要连一条边到对立点;即如果选a必输,则连一条边a->a‘总之,要不断找矛盾贴贴很挫的代码View Code #include<stdio.h>#include<string.h>#include<vector>#include<algorithm>using namespace std;const int MAX = 20010;vector<int> edge[MAX];int st[MAX];int dfn[MAX],low[MAX] Read More
posted @ 2011-11-25 15:45 Because Of You Views(367) Comments(0) Diggs(0) Edit
很奇怪很奇怪的一件事情输入的时候用scanf ("%s%s",s1,s2)竟然错了最后无语的换了下输入,建图不难的#include<stdio.h>#include<string.h>#include<vector>#include<algorithm>using namespace std;const int MAX = 2011;vector<int> edge[MAX];int st[MAX];int dfn[MAX],low[MAX];int top,btype,tdfn;//btype:Á Read More
posted @ 2011-11-25 15:40 Because Of You Views(217) Comments(0) Diggs(0) Edit
矩阵相乘模板#include <cstdio>#include <cstring># define ld __int64struct Matrix{ ld a[2][2]; void init() { a[0][0]=a[1][0]=a[0][1]=1; a[1][1]=0; }};Matrix matrix_mul(Matrix a,Matrix b){ int i,j,k; Matrix ans; for(i=0;i<2;i++) { for(j=0;j<2;j++) { ans.a[i][j]=0; for(k=0;k<2;k++) ans.a[ Read More
posted @ 2011-11-25 13:11 Because Of You Views(239) Comments(0) Diggs(0) Edit
#include<stdio.h>#include<string.h>#include<algorithm>#include<queue>using namespace std;#define SIZE 1010const int inf = 100000000;struct node{ int s,t,f,w; int next;}edge[100010];int head[2010];int mincost,tot;int s,t,pre[2010];void add(int s,int t,int w,int f){ edge[tot].f Read More
posted @ 2011-11-24 23:49 Because Of You Views(607) Comments(0) Diggs(0) Edit
蛮简单的dp,只是要注意会超intdp[i][j]代表i个数以j结尾的数列个数#include<stdio.h>#include<string.h>__int64 dp[11][2001];int i,j,k;void init(){ memset(dp,0,sizeof(dp)); for(i=1;i<=2000;i++) dp[1][i]=1; for(i=2;i<=10;i++) { for(j=i;j<=2000;j++) { for(k=1;k<=j/2;k++) { dp[i][j]+=dp[i-1][k]; } } }}int ma Read More
posted @ 2011-11-24 10:36 Because Of You Views(333) Comments(0) Diggs(0) Edit
简单的方法来自http://poj.org/showmessage?message_id=156697#include<stdio.h>#include<string.h>int dp[100010];int num[110],v[110];int used[100010];int main(){ int n,m,i,j; while(scanf("%d%d",&n,&m),(n||m)){ for(i=0;i<n;i++) scanf("%d",&v[i]); for(i=0;i<n;i++) Read More
posted @ 2011-11-21 03:18 Because Of You Views(321) Comments(0) Diggs(0) Edit
The Fewest CoinsTime Limit:2000MSMemory Limit:65536KTotal Submissions:2618Accepted:770DescriptionFarmer John has gone to town to buy some farm supplies. Being a very efficient man, he always pays for his goods in such a way that the smallest number of coins changes hands, i.e., the number of coins h Read More
posted @ 2011-11-21 02:53 Because Of You Views(320) Comments(0) Diggs(0) Edit
O(nlogn)的算法关键是它建立了一个数组temp[],temp[i]表示长度为i的不下降序列中结尾元素的最小值,用top表示数组目前的长度,算法完成后top的值即为最长不下降子序列的长度。 设当前的以求出的长度为top,则判断num[i]和temp[top]: 1.如果num[i]>=temp[top],即num[i]大于长度为top的序列中的最后一个元素,这样就可以使序列的长度增加1,即top++,然后现在的temp[top]=num[i]; 2.如果num[i]<temp[top],那么就在temp[1]...temp[top]中找到最大的j,使得temp[j]<nu Read More
posted @ 2011-11-20 22:25 Because Of You Views(3597) Comments(0) Diggs(1) Edit
上一页 1 ··· 22 23 24 25 26 27 28 29 30 ··· 42 下一页