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

2011年5月11日

poj 3666

摘要: 转移的时候,就是:dp[i][j] = min{dp[i - 1][0...j] + ‍abs(A[i] - T[j])},其中A[i]是第i个数的原始值,T[j]是j离散化前的值。代码:#include<iostream>#include<fstream>using namespace std;int n;long long a[2001];long long b[2001];int cmp(const void *a,const void *b){ return *(long long*)a-*(long long*)b;}long long dp[2001][20 阅读全文

posted @ 2011-05-11 10:56 宇宙吾心 阅读(726) 评论(0) 推荐(0)

2011年5月10日

poj 3659

摘要: 有意思的树形dp代码:#include<iostream>#include<fstream>using namespace std;int n;struct e{ int data; e *next;};e edge[10001];int dp[10001][3];int v[10001];void solve(int s){ int i,j,k; v[s]=1; e *p=edge[s].next; dp[s][1]=1; dp[s][0]=0; dp[s][2]=10000000; if(!p) return; k=-1000000; int f=0; dp[s][ 阅读全文

posted @ 2011-05-10 14:24 宇宙吾心 阅读(421) 评论(0) 推荐(0)

poj 3140

摘要: 简单题代码:#include<iostream>#include<fstream>#include<vector>using namespace std;vector<long long> edge[100001];long long value[100001];int v[100001];long long dp[100001];long long n,m;long long ok(long long s){ if(s<0) return -s; return s;}long long solve(long long s){ long l 阅读全文

posted @ 2011-05-10 13:40 宇宙吾心 阅读(278) 评论(0) 推荐(0)

poj 1155

摘要: 树形dp大意:某电台要广播一场比赛,该电台网络是由N个网点组成的一棵树,其中M个点为客户端,其余点为转发站。客户端i愿支付的钱为pay[i],每一条边需要的花费固定,问电台在保证不亏损的情况下,最多能使多少个客户端接收到信息?广播台所在的节点编号为1分析:树形DP1.user[i].dp[j]表示从转发站i开始计算,满足其子树中j个顾客的最大报酬 分析节点i的孩子节点s a.放弃该孩子s,值不变 b.取该孩子的若干的节点:user[i].dp[j-k]+user[s].dp[k]-cost[i][j](cost[i][j])为 连通该边所需要付出的代价。 综上: user[i].dp[j]=m 阅读全文

posted @ 2011-05-10 13:15 宇宙吾心 阅读(983) 评论(1) 推荐(0)

2011年5月9日

poj 2823

摘要: 单调队列的经典题代码:#include<iostream>#include<fstream>#include<queue>using namespace std;#define MAX 1000000int a[1000001];int minn[1000001];int maxx[1000001];int n,m,f1,r1,f2,r2;void read(){// ifstream cin("in.txt"); int i,j,k; scanf("%d%d",&n,&m); for(i=1;i< 阅读全文

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

poj 1733

摘要: 并查集代码:#include<iostream>#include<fstream>#include<vector>using namespace std;int f[10001];int d[10001];struct e{ int s,t;};vector<e> a[9950];int n,m;void init(){ int i,j,k; for(i=1;i<=10000;i++) { f[i]=i; }}int find(int s){ int i,j,k; s=s%9949; if(a[s].size()==0) { e b; b. 阅读全文

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

poj 3250

摘要: 同3494代码:#include<iostream>#include<fstream>using namespace std;long long a[80010];int lef[80010];int n;void read(){// ifstream cin("in.txt"); int i,j,k; cin>>n; for(i=1;i<=n;i++) cin>>a[n-i+1]; a[0]=a[n+1]=2000000000; for(i=1;i<=n;i++) lef[i]=i; for(i=1;i<= 阅读全文

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

poj 2796

摘要: 同3494代码:#include<iostream>#include<fstream>using namespace std;long long a[100011],lef[100011],rig[100011];long long n;void read(){// ifstream cin("in.txt"); long long i,j,k; scanf("%lld",&n); for(i=1;i<=n;i++) scanf("%lld",&a[i]); for(i=1;i<=n 阅读全文

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

poj 3494

摘要: 一类连续最大区域问题代码:#include<stdio.h>#include<fstream>int a[2001][2001];int n,m;int h[2001][2001];int left[2001],right[2001];int max(int s,int t){ if(s<t) return t; else return s;}void read(){// ifstream cin("in.txt"); int i,j,k; while(scanf("%d%d",&n,&m)!=EOF){ f 阅读全文

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

poj 1686

摘要: 判断两个表达式是否相同。代码:#include<iostream>#include<fstream>#include<stack>using namespace std;char c1[2000],c2[2000];char s1[2000],s2[2000],s[2000];int a[126];int ok(char c){ if(c>='0'&&c<='9') return 1; if(c>='a'&&c<='z') return 1 阅读全文

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

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

导航