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

2011年5月6日

poj 3342

摘要: 宴会邀请,求最多能邀请多少人? 条件是具有主仆关系的人不能同时被邀请代码:#include<iostream>#include<fstream>#include<string>#include<map>using namespace std;int n;int g[201][201];int dp[201][2];string str1,str2;void solve(int s){ int i,j,k; dp[s][0]=0; dp[s][1]=1; for(i=1;i<=n;i++) if(g[s][i]) { solve(i); dp 阅读全文

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

poj 3356

摘要: 题意:给出两个字符串x和y,要求使用最少的操作使得X变为y,求解该最少操作数.#include<iostream>#include<fstream>using namespace std;int dp[1001][1001];char a[1010],b[1010];int n1,n2;void read(){// ifstream cin("in.txt"); int i,j,k; while(cin>>n1>>a>>n2>>b) { for(i=1;i<=n1;i++) dp[i][0]=i; 阅读全文

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

poj 3638

摘要: 一个地图软件需要需要存储h个房子的坐标信息,但为节约存储空间可以只存储其中的m个房子的坐标信息其他房子的坐标信息可以由插值得到。问怎样选择这个m个房子,使得所有房子的插值误差之和最小, 输出最小的插值误差均值。n^3 dp代码:#include<iostream>#include<fstream>using namespace std;int n,m;double dp[201][201];double a[201];double w[201][201];double fabs(double s){ if(s<0) return -s; else return s 阅读全文

posted @ 2011-05-06 15:41 宇宙吾心 阅读(291) 评论(0) 推荐(0)

2011年5月5日

poj 1157

摘要: 题意:现在有F束不同品种的花束,同时有至少同样数量的花瓶被按顺序摆成一行,其位置固定于架子上,并从1至V按从左到右顺序编号,V是花瓶的数目(F≤V)。花束可以移动,并且每束花用1至F的整数唯一标识。标识花束的整数决定了花束在花瓶中排列的顺序,如果i<j,花束i必须放在花束j左边的花瓶中。每个花瓶只能放一束花。如果花瓶的数目大于花束的数目,则多余的花瓶空置。 每一个花瓶都具有各自的特点。因此,当各个花瓶中放入不同的花束时,会产生不同的美学效果,并以一美学值(一个整数)来表示,空置花瓶的美学值为零。为取得最佳美学效果,必须在保持花束顺序的前提下,使花束的摆放取得最大的美学值。请求出具有最大美 阅读全文

posted @ 2011-05-05 16:07 宇宙吾心 阅读(1243) 评论(0) 推荐(1)

2011年5月4日

poj 1384

摘要: 完全背包。代码:#include<iostream>#include<fstream>using namespace std;int dp[10001];int e,f;int p[501],w[501];int n;void read(){// ifstream cin("in.txt"); int i,j,k; int cas; cin>>cas; while(cas--){ cin>>e>>f; cin>>n; for(i=1;i<=n;i++) cin>>p[i]>> 阅读全文

posted @ 2011-05-04 20:22 宇宙吾心 阅读(286) 评论(0) 推荐(0)

poj 1631

摘要: 最长不降子序列。代码:#include<iostream>#include<fstream>using namespace std;int a[40001],b[40001];int n;int find(int s,int value){ int i=0,k; while(i<=s) { k=(i+s)>>1; if(b[k]>value) s=k-1; else i=k+1; } return s;} void read(){ ifstream cin("in.txt"); int i,j,k; cin>>k; 阅读全文

posted @ 2011-05-04 19:37 宇宙吾心 阅读(367) 评论(0) 推荐(0)

poj 1661

摘要: 定义好状态.代码:#include<iostream>#include<fstream>using namespace std;struct e{ int left,right;};e dp[1010];struct a{ int x,y,h;};a map[1010];int cmp(const void *p,const void *q){ a *s=(a*)p; a *t=(a*)q; return t->h-s->h;}int n,maxx;int solve(int s,int f){ int x,y,h,i,j,k; if(f) x=map[s] 阅读全文

posted @ 2011-05-04 19:15 宇宙吾心 阅读(350) 评论(1) 推荐(0)

poj 1609

摘要: 题意:抽象的说,就是给出一列数对 ,求出其最长的递增序列的长度。用偏序定理,再LIS(nlogn).代码:#include<iostream>#include<fstream>using namespace std;int n;struct e{ int s,t;};e a[10001];int cmp(const void *a,const void *b){ e *s=(e*)a; e *t=(e*)b; if(s->s!=t->s) return s->s-t->s; else return s->t-t->t;} int b[ 阅读全文

posted @ 2011-05-04 18:06 宇宙吾心 阅读(467) 评论(0) 推荐(0)

2011年5月2日

poj 1732

摘要: dp代码:#include<iostream>#include<fstream>using namespace std;int dp[101];char c[110];char hash[30]="22233344115566070778889990";int road[101];int n;char a[50001][51];char b[50001][51];void print(int s){ if(s!=0) { print(s-strlen(a[road[s]])); cout<<b[road[s]]<<' 阅读全文

posted @ 2011-05-02 17:55 宇宙吾心 阅读(376) 评论(0) 推荐(0)

poj 1837

摘要: 题意:现在有一个天平,还有C个挂钩和G个砝码,求解又多少种方法能使得天平平衡(注意必须使用所有的砝码) dp[i][j]表示在挂上前i个物体的时,平衡度为j(j>0时表示左边重,j=0时表示天平平衡,j<0时表示右边重)时挂法的数量,而根据题意可以确定j的取值范围为:[-7500,7500],于是可以得到状态转移方程为: dp[i][j]+=(dp[i-1][j-p[k]*g[i]]), p[k]表示第k个挂钩的位置,g[i]为第i个砝码的重量 由于j-p[k]*g[i]可能为负数,因此统一加上7500,那么初始状态dp[0][7500]=1(此时表示天平平衡),表示不用物体且使得 阅读全文

posted @ 2011-05-02 16:02 宇宙吾心 阅读(350) 评论(0) 推荐(0)

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

导航