上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 36 下一页

2011年5月9日

poj 3253

摘要: 题目就是给一块木板,它有一个长度,现在要把它据成一个个指定长度的木板,但每次锯一块木板的时候要收取木板长度那么多钱。现在给定小木板的个数,以及每个小木板的长度,问从一个全长为所有木板和的木板锯成这些小木板,需要交的最少金额是多少。算法:这题其实就是让你构造哈夫曼树,这样的代价是最小的。但我们不必真的去构造哈夫曼树,我们只需要了解我们在树中要得到的东西就行了。在这题中我们需要从哈夫曼树的最底层的子树根结点值开始加起,每次只加根结点的值,一直走到总根结点就行,也就是说,每次取最小的两个数相加。可以用优先队列实现。代码:#include<iostream>#include<fstr 阅读全文

posted @ 2011-05-09 12:05 宇宙吾心 阅读(193) 评论(0) 推荐(0)

poj 2247

摘要: 经典题,注意输出代码:#include<iostream>#include<fstream>using namespace std;long long a[5843];long long min(long long s,long long t){ if(s<t) return s; return t;}void read(){// ifstream cin("in.txt"); int i,j,k; int n1,n2,n3,n4; n1=1;n2=1;n3=1;n4=1; a[1]=1; for(i=2;i<=5842;i++) { a 阅读全文

posted @ 2011-05-09 11:32 宇宙吾心 阅读(332) 评论(0) 推荐(0)

2011年5月7日

poj 2192

摘要: 简答dp代码:#include<iostream>#include<fstream>using namespace std;char a[201],b[201],c[401];bool dp[201][401];void read(){// ifstream cin("in.txt"); int i,j,k; int cas; cin>>cas; for(k=1;k<=cas;k++) { cin>>a>>b>>c; int n1=strlen(a); int n2=strlen(b); mems 阅读全文

posted @ 2011-05-07 18:20 宇宙吾心 阅读(306) 评论(0) 推荐(0)

poj 2475

摘要: 上下文无关文法。经典。代码:#include<iostream>#include<fstream>using namespace std;char c[300];int map[201][201][4];int Set(int ,int);int ElemList (int,int);int List(int,int);int Elem(int,int);int Atom(int,int);int Atom(int s,int t){ if(s==t) return 1; return 0;}int Elem(int s,int t){ if(map[s][t][3]& 阅读全文

posted @ 2011-05-07 17:22 宇宙吾心 阅读(362) 评论(0) 推荐(0)

poj 2948

摘要: dp水题代码:#include<iostream>#include<fstream>using namespace std;int dp[501][501];int a[501][501];int b[501][501];int n,m;void read(){// ifstream cin("in.txt"); int i,j,k; while(cin>>n>>m){ if(n==0) return; for(i=1;i<=n;i++) for(j=1;j<=m;j++) scanf("%d" 阅读全文

posted @ 2011-05-07 15:01 宇宙吾心 阅读(304) 评论(0) 推荐(0)

poj 3042

摘要: 经典dp。代码:#include<iostream>#include<fstream>using namespace std;int a[1010];int dp[1010][1010][2];int v[1010][1010][2];int cmp(const void *a,const void *b){ return *(int*)a-*(int*)b;}int n,m;int solve(int s,int t,int f){ int i,j,k; if(v[s][t][f]) return dp[s][t][f]; v[s][t][f]=1; if(f==0) 阅读全文

posted @ 2011-05-07 14:26 宇宙吾心 阅读(337) 评论(0) 推荐(0)

poj 3088

摘要: 第一类斯特灵数S(n,m)就是把n元集合分成m部的个数,有递推关系S(n,m)=S(n-1,m-1)+mS(n-1,m).所求还要全排列一下.再乘以m!就可以了累加1~B个数全部用上,就是结果.F(B)=sum(C(B,i)*(Sum(Stir( i,j )* j ! ) ) )就是结果.代码:#include<iostream>#include<fstream>#include<cmath>using namespace std;long long dp[13][13];long long ans[13];long long fun(long long s 阅读全文

posted @ 2011-05-07 13:36 宇宙吾心 阅读(283) 评论(0) 推荐(0)

2011年5月6日

poj 3257

摘要: dp代码:#include<iostream>#include<fstream>using namespace std;int l,n,b;struct e{ int w,x,f,c;};e a[10001];int dp[1001][1001];int cmp(const void *a,const void *b){ e *s=(e *)a; e *t=(e *)b; return s->x-t->x;}void read(){// ifstream cin("in.txt"); int i,j,k; cin>>l> 阅读全文

posted @ 2011-05-06 21:49 宇宙吾心 阅读(227) 评论(0) 推荐(0)

poj 3267

摘要: 题意:求最少去掉多少字母,能使句子可由单词表中的单词连成。代码:#include<iostream>#include<fstream>using namespace std;char c[310];char a[601][30];int dp[301];int n,m;int ok(int s,int t){ int i,j,k; j=strlen(a[t])-1; for(i=s;j>=0&&i>=0;i--) if(c[i]==a[t][j]) { j--; if(j==-1) return i; } return -1;} void r 阅读全文

posted @ 2011-05-06 21:00 宇宙吾心 阅读(266) 评论(0) 推荐(0)

poj 3298

摘要: 贪心代码:#include<iostream>#include<fstream>using namespace std;int a[30001];int n;void read(){// ifstream cin("in.txt"); int i,j,k; int cas; cin>>cas; while(cas--) { cin>>n; for(i=1;i<=n;i++) cin>>a[i]; j=1;k=a[1];i=2; int ans=1; while(i<=n) { if(k<a[i]& 阅读全文

posted @ 2011-05-06 17:31 宇宙吾心 阅读(167) 评论(0) 推荐(0)

上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 36 下一页

导航