随笔分类 -  动态规划

上一页 1 2 3 4 5 6 下一页

hdu 3336
摘要:KMP+dp经典#include<stdio.h>#include<string.h>#define mod 10007char t[200010];int next[200010];int num[200010];int cnt;void get_next(char T[],int len,int next[]){ int i=0,j=-1; next[0]=-1; while(i<len) { if(j==-1 || T[i]==T[j]) { j++; i++; next[i]=j; } else j=next[j]; }}void main(){int c 阅读全文

posted @ 2011-08-10 17:55 宇宙吾心 阅读(178) 评论(0) 推荐(0)

hdu 3401
摘要:dp单调队列的优化经典 阅读全文

posted @ 2011-08-09 20:49 宇宙吾心 阅读(152) 评论(0) 推荐(0)

zoj 2059
摘要:#include<iostream>#include<fstream>#include<memory.h>using namespace std;int n;int a[101];int dp[101][4004];void read(){// ifstream cin("in.txt"); int i,j,k; while(cin>>n) { if(n<0) return; if(n<=1) { cout<<"Sorry"<<endl; continue; } for( 阅读全文

posted @ 2011-07-10 21:52 宇宙吾心 阅读(193) 评论(0) 推荐(0)

zoj 1985
摘要:#include<iostream>#include<fstream>using namespace std;int n;long long h[100003];int lef[100003];int rig[100003];void read(){// ifstream cin("in.txt"); int i,j,k; while(scanf("%d",&n)) { if(n==0) return; for(i=1;i<=n;i++) scanf("%lld",&h[i]); h[0] 阅读全文

posted @ 2011-07-10 17:37 宇宙吾心 阅读(213) 评论(0) 推荐(0)

zoj 1880
摘要:#include<iostream>#include<fstream>#include<memory.h>using namespace std;int n,m;int a[101];bool dp[51][22951];int abs(int s){ if(s<0) return -s; else return s;}void read(){// ifstream cin("in.txt"); int i,j,k; while(cin>>n) { int sum=0; for(i=1;i<=n;i++) { ci 阅读全文

posted @ 2011-07-10 17:15 宇宙吾心 阅读(209) 评论(0) 推荐(0)

zoj 1953
摘要:#include<iostream>#include<fstream>using namespace std;char c1[101],c2[101];int dp[103][103];int n1,n2;void print(int s,int t){ int i; if(s==0&&t==0) return; if(s==0) { for(i=0;i<t;i++) cout<<c2[i]; return; } if(t==0) { for(i=0;i<s;i++) cout<<c1[i]; return; } if 阅读全文

posted @ 2011-07-10 17:14 宇宙吾心 阅读(226) 评论(0) 推荐(0)

zoj 1883
摘要:#include<iostream>#include<fstream>using namespace std;int n,m;double dp[10][101];void read(){// ifstream cin("in.txt"); int i,j,k; while(cin>>m>>n) { for(i=0;i<=m;i++) dp[i][1]=1; for(i=2;i<=n;i++) for(j=0;j<=m;j++) { dp[j][i]=dp[j][i-1]; if(j>0) dp[j][ 阅读全文

posted @ 2011-07-10 17:14 宇宙吾心 阅读(118) 评论(0) 推荐(0)

zoj 1642
摘要:#include<iostream>#include<fstream>#include<cstring>using namespace std;int n;int map[300];char c1[2001],c2[2001];int dp[2002][2002];void read(){// ifstream cin("in.txt"); int i,j,k; char c; while(cin>>n) { for(i=1;i<=n;i++) { cin>>c>>j; map[(int)c]=j 阅读全文

posted @ 2011-07-09 15:40 宇宙吾心 阅读(160) 评论(0) 推荐(0)

zoj 1636
摘要:#include<iostream>#include<fstream>#include<stdio.h>using namespace std;long long map[501][501];int n,m;void read(){// ifstream cin("in.txt"); int i,j,k,s,t,i1,j1; int cas; scanf("%d",&cas); for(s=1;s<=cas;s++) { printf("Case %d:\n",s); scanf(&q 阅读全文

posted @ 2011-07-09 15:21 宇宙吾心 阅读(160) 评论(0) 推荐(0)

zoj 1602
摘要:#include<iostream>#include<fstream>using namespace std;int n;long long dp[101][101];int a[101];void read(){// ifstream cin("in.txt"); int i,j,k,s; while(cin>>n) { for(i=1;i<=n;i++) cin>>a[i]; for(s=2;s<=n;s++) for(i=1;i+s<=n;i++) { j=i+s; dp[i][j]=-1; for(k 阅读全文

posted @ 2011-07-09 15:21 宇宙吾心 阅读(268) 评论(0) 推荐(0)

zoj 1733
摘要:#include<iostream>#include<fstream>#include<cstring>using namespace std;char c1[1001],c2[1001];int dp[1011][1011];void read(){// ifstream cin("in.txt"); int i,j,k; int n1,n2; while(cin>>c1>>c2) { n1=strlen(c1); n2=strlen(c2); for(i=1;i<=n1;i++) for(j=1;j< 阅读全文

posted @ 2011-07-09 15:20 宇宙吾心 阅读(266) 评论(0) 推荐(0)

zoj 1524
摘要:#include<iostream>#include<fstream>#include<memory.h>using namespace std;int a[101];int p[100001];double q[100001];double dp[2][100001];int n,m;void read(){// ifstream cin("in.txt"); int i,j,k; while(cin>>n>>m) { if(n==0&&m==0) return; for(i=1;i<=n; 阅读全文

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

zoj 1563
摘要:#include<iostream>#include<fstream>using namespace std;int p[101];int sum[101];int dp[101];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>>j>>p[i]; sum[i]=sum[i-1]+j; } for(i=1 阅读全文

posted @ 2011-07-08 16:23 宇宙吾心 阅读(182) 评论(0) 推荐(0)

zoj 1196
摘要:#include<iostream>#include<fstream>#include<cmath>#include<memory.h>using namespace std;int a[201];int w[201][201];int dp[201][31];int n,m;int abs(int s){ if(s>0) return s; else return -s;}void read(){// ifstream cin("in.txt"); int i,j,k,s,t; int cas=0; while(cin 阅读全文

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

zoj 1163
摘要:#include<iostream>#include<fstream>using namespace std;double dp[501][501];int n;void read(){// ifstream cin("in.txt"); int i,j,k; for(i=0;i<=500;i++) dp[0][i]=1; for(i=1;i<=500;i++) for(j=1;j<=500;j++) { dp[i][j]=dp[i][j-1]; if(i>=j) dp[i][j]+=dp[i-j][j-1]; } while 阅读全文

posted @ 2011-07-08 14:42 宇宙吾心 阅读(212) 评论(0) 推荐(0)

poj 2677
摘要:TSP#include<iostream>#include<fstream>#include<cmath>using namespace std;double dp[101][101];int x[101],y[101];double ok(int s,int t){ return sqrt(1.*(x[s]-x[t])*(x[s]-x[t])+(y[s]-y[t])*(y[s]-y[t]));}int n;void read(){// ifstream cin("in.txt"); int i,j,k; while(cin>> 阅读全文

posted @ 2011-06-15 17:33 宇宙吾心 阅读(262) 评论(0) 推荐(0)

poj 1952
摘要:dp#include<iostream>#include<fstream>using namespace std;int len[5001],time[5001];int a[5001];int n;void read(){// ifstream cin("in.txt"); int i,j,k; cin>>n; for(i=1;i<=n;i++) cin>>a[i]; for(i=1;i<=n;i++) { len[i]=1; time[i]=1; } for(i=1;i<=n;i++) for(j=i-1 阅读全文

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

poj 1112
摘要:代码:#include<iostream>#include<fstream>#include<cmath>using namespace std;int n;struct e{ int data; e *next;};e edge[101];int v[101];void add(int s,int t){ e *p=new e; p->data=t; p->next=edge[s].next; edge[s].next=p;}int x[101],y[101],mark[101][101];int dfs(int s,int kind,int 阅读全文

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

poj 1322
摘要:题意是,c种不同颜色的巧克力,每种巧克力同样多,把巧克力一个一个拿到桌子上,当发现有相同颜色就全吃掉,求取出了n个后,还剩m个在桌子的概率。直接求概率是不可能,要用到DP。动态转移方程:p[n][m]表示n个巧克力,还剩m个在台上的概率p[n][m]=p[n-1][m-1]*p1+p[n-1][m+1]*p2p1=(c-m+1)/c,p2=(m+1)/c当m+n为奇时,概率为0特别注意:当n很大时,概率处于稳定,但是还是要处理奇偶性代码:#include<iostream>#include<fstream>using namespace std;double dp[10 阅读全文

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

poj 2836
摘要:因为要面积最小,一定是以每次覆盖两个点为主,并让这两个点在矩形的对角。此题不可以出现面积为0的矩形,所以当出现x[i]==x[j]或者y[i]==y[j]时,让它为0的这边的边长变成1。代码:#include<iostream>#include<fstream>using namespace std;int n,m;int x[16],y[16];int state[300],value[300];void ok(int s,int t){ int i,j,k; k=(1<<(s-1))+(1<<(t-1)); for(i=1;i<=n;i 阅读全文

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

上一页 1 2 3 4 5 6 下一页

导航