03 2013 档案

PKU POJ 2479 Maximum sum 最大连续子序列和
摘要:这里子序列不能为空,至少要一个,特殊一点。View Code #include <iostream>#include <stdio.h>using namespace std;__int64 n,a[50005],dpl[50005],dpr[50005];int main(){ __int64 T,i,sum,mmax; scanf("%I64d",&T); while (T--) { scanf("%I64d",&n); for (i=0;i<n;++i) scanf("%I64d", 阅读全文

posted @ 2013-03-30 20:20 Deller 阅读(137) 评论(0) 推荐(0)

PKU POJ 3903 Stock Exchange 最长递增子序列
摘要:必须要nlogn算法才能过View Code #include <iostream>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace std;int L,a[100005];int list[100005],numoflist;int bsearch(int value){ int l=0,r=numoflist-1,mid; while (l<r) { mid=(l+r)>>1; if (list[mid]>=value) 阅读全文

posted @ 2013-03-28 18:55 Deller 阅读(144) 评论(0) 推荐(0)

PKU POJ 1458 Common Subsequence LCA 最长公共子序列
摘要:View Code #include <iostream>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace std;int LCS(char x[],int l1,char y[],int l2){ int i,j,p,dp[2][1005]; memset(dp[0],0,sizeof(dp[0])); for (j=0,p=1;j<l2;++j) { dp[p][0]=0; for (i=0;i<l1;++i) { ... 阅读全文

posted @ 2013-03-28 16:07 Deller 阅读(162) 评论(0) 推荐(0)

PKU POJ 2531 Network Saboteur 搜索
摘要:暴力搜索也能过,剪枝去掉重复搜索,可以到1s内View Code #include <iostream>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace std;int n,c[25][25];bool t[25];int mmax;void dfs(int p,int x){ int i; if(x==0||n-p==x) { if(x>0) for (i=p;i<n;++i) t[i]=true; ... 阅读全文

posted @ 2013-03-19 16:19 Deller 阅读(140) 评论(0) 推荐(0)

PKU POJ 1088 滑雪 搜索
摘要:#include <iostream>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace std;int r,c;int map[105][105],height[105][105];int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};inline bool judge(int x,int y){ return x>=0&&y>=0&&x<r&&y< 阅读全文

posted @ 2013-03-18 21:53 Deller 阅读(164) 评论(0) 推荐(0)

PKU POJ 1002 487-3279 水题
摘要:#include <iostream>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace std;int a[100005];int t(char c){ if(c<'Q') return (c-'A')/3+2; else return (c-'B')/3+2;}int trans(char s[]){ int res=0; for (int i=0;i<strlen(s);++i) { i 阅读全文

posted @ 2013-03-14 21:13 Deller 阅读(143) 评论(0) 推荐(0)

PKU POJ 1946 Cow Cycling DP
摘要:题目让一队牛(n只)骑车,只要有一个过终点(跑d圈),就算完成任务。每只牛刚开始的能量为e,当队伍速度为x圈/分钟时,领头的消耗为x^2能量/分钟,后面的消耗为x。求最快完成时间。dp[i][j][k]代表还剩i只牛没领跑,已经跑了j圈,领头的牛还有k能量的情况下最短用时。#include <iostream>using namespace std;int dp[25][105][105];int mmin(int a,int b){ if (a==0) return b; else return a<b?a:b;}int main(){ int ... 阅读全文

posted @ 2013-03-09 16:10 Deller 阅读(166) 评论(0) 推荐(0)

PKU POJ 1671 Rhyme Schemes DP
摘要:基础DP,从长度为i-1的方案数得到长度为i的方案数,dp[i][j]长度为i有j种字母组成的方案数。#include <iostream>using namespace std;double dp[1000][1000];void init(){ int i,j; dp[1][1]=1; for (i=2;i<1000;++i) { dp[i][i]=dp[i][1]=1; for (j=2;j<i;++j) dp[i][j]=dp[i-1][j-1]+dp[i-1][j]*j; }}int main(){ ... 阅读全文

posted @ 2013-03-08 17:43 Deller 阅读(147) 评论(0) 推荐(0)

POJ PKU 1959 Darts 暴力枚举
摘要:直接暴力枚举即可,这里只需要要注意的是不要重复枚举某种情况。#include <iostream>using namespace std;int a[63]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,2 ,4 ,6 ,8 ,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,3 ,6 ,9 ,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,50,25};int solve(int score){ int i,j,k,re 阅读全文

posted @ 2013-03-08 15:55 Deller 阅读(179) 评论(0) 推荐(0)

PKU POJ 2378 Tree Cutting 搜索
摘要:任选一个节点作为树根开始搜索,保存每个节点的各个子树大小。最后枚举各个节点,找出所有子树大小均不超过n/2并且除掉这些子树及自身剩下的树的大小也不超过n/2的节点输出。#include<iostream>#include <vector>#define M 10005using namespace std;int n;bool flag[M];vector<int> son[M];vector<int> cnt[M];int dfs(int node){ flag[node]=true; int i,res=1; for (i=0;i<so 阅读全文

posted @ 2013-03-06 12:35 Deller 阅读(161) 评论(0) 推荐(0)

PKU POJ 1989 The Cow Lineup 贪心策略
摘要:将输入序列划分为若干段,每段包含1~k至少各一个。有几个这样的段(如x)就能形成x长度的任意序列。所以最短不存在的序列长度为x+1。#include<iostream>using namespace std;bool flag[10000];int main(){ int n,k,tmp,cnt,len; while (scanf("%d%d",&n,&k)!=EOF) { memset(flag,true,k+1); cnt=0; len=0; while (n--) { scanf... 阅读全文

posted @ 2013-03-04 20:22 Deller 阅读(139) 评论(0) 推荐(0)

openCV2.4.3安装办法
摘要:openCV2.4.3安装办法:第一步:下载openCV2.4.3;第二步:解压到要安装的目录,即可完成安装,如:D:\opencv;第三步:配置系统环境变量,在PATH中加入:D:\opencv\build\x86\vc10\bin以上三步即完成openCV2.4.3的安装,现在就可以打开VS2010进行使用。新建一个C++工程时,修改项目属性,在include下加入以下三条:D:\opencv\build\include\opencv2;D:\opencv\build\include\opencv;D:\opencv\build\include;在library下加入一条:D:\openC 阅读全文

posted @ 2013-03-04 18:29 Deller 阅读(297) 评论(0) 推荐(0)

POJ PKU 3176 Cow Bowling DP
摘要:二维基础DP。#include<iostream>using namespace std;inline int mmax(int a,int b){ return a>b?a:b;}int main(){ int n,a[355][355],i,j; while (scanf("%d",&n)!=EOF) { for (i=0;i<n;++i) for(j=0;j<=i;++j) scanf("%d",&a[i][j]); for (i=1;i<n;++i) { ... 阅读全文

posted @ 2013-03-04 18:27 Deller 阅读(131) 评论(0) 推荐(0)

POJ PKU 2029 Get Many Persimmon Trees DP
摘要:DP预处理矩阵,使每个节点存储左上上角的总数,再枚举得结果。#include<iostream>using namespace std;int w,h,map[105][105];int main(){ int n,i,j,s,t; while (scanf("%d",&n)!=EOF&&n) { scanf("%d%d",&w,&h); for(i=0;i<=w;++i) for(j=0;j<=h;++j) map[i][j]=0; while (n--) { ... 阅读全文

posted @ 2013-03-04 18:26 Deller 阅读(147) 评论(0) 推荐(0)

PKU POJ 2346 Lucky tickets DP
摘要:DP统计1~5位数的各位数字和的分布。#include <stdio.h>#include <memory.h>#include <iostream>int main(){ int i,j,k,dp[6][50],m,n,cnt; memset(dp,0,sizeof(dp)); for (i=0;i<=9;++i) dp[1][i]=1; m=9; for(i=2;i<6;++i) { for (j=0;j<=9;++j) for(k=0;k<=m;++k) dp[i][k+j... 阅读全文

posted @ 2013-03-04 18:23 Deller 阅读(197) 评论(0) 推荐(0)

PKU POJ 1664 放苹果 DP
摘要:题目意思很明确:给定一个正整数n,求将其划分为m份的不同方法数。这里是整数分割(整数划分)的方法。动态规划方法(1) 最原始的动态规划:考虑划分过程中的最大数 k,令dp[i][j][k]表示将整数j划分成 i 份,而最后一个数最大为 k 的划分方案总数。那么:该状态(i, j, k)可由前面“i-1”份的“j-k”加上“一份k”而来,因此当前状态的方案总数就等于“j-k”划分为i-1份的所有最大加数小于等于k的方案数至和。得到状态转移方程:dp[i][j][k] = SUM{ dp[i-1][j-k][l] | 0 <= l <= k }DP算法1: O(n^3*m)Set al 阅读全文

posted @ 2013-03-04 18:21 Deller 阅读(249) 评论(0) 推荐(0)

PKU POJ 2414 Phylogenetic Trees Inherited DP
摘要:英语水平有限,题目意思看了下面博客才懂http://www.cnblogs.com/Lyush/archive/2013/01/11/2857012.html意思是:给定N个字符串,N为2的幂,每个字符串长度为L,这N个字符串 是一棵完全二叉树的叶子节点,现在问树的内部在同样要填入长度为L的字符串的情况下,最少的花费是多少,根节点是什么。用DP从叶子节点向根节点计算,dp数组从根1开始,dp[i][j]是某个叶子节点的第j个字母的所有可能取值。用32位整数最后26位代表是否取某个字母。#include<iostream>#include <string.h>#inclu 阅读全文

posted @ 2013-03-04 18:15 Deller 阅读(185) 评论(0) 推荐(0)

PKU POJ 1240 Pre-Post-erous! 搜索
摘要:题目意思很明确,给点一个m叉树的前序访问s1和后续访问s2,计算出所有可能的m叉树的总数。用搜索分层进行可以计算,这里注意组合数的计算,不要溢出。#include<iostream>#include <string.h>#include <string>using namespace std;int m;char s1[30],s2[30];int c(int r,int n){ int res=1; for (int i=1;i<=r;++i) res=res*(n-r+i)/i; return res;}int searchin2(char c){ 阅读全文

posted @ 2013-03-04 18:14 Deller 阅读(152) 评论(0) 推荐(0)

PKU POJ 2181 Jumping Cows DP
摘要:题目意思是从数列中选出一个子序列,然后堆该数列依次加一个减一个,最后得到的和最大。dp[0]记录之前处理过的数中,加一个数后得到的最大值;dp[1]则是记录减一个数后的最大值。#include<iostream>#include <string.h>#include <string>using namespace std;inline int mmax(int a,int b){ return a>b?a:b;}int main(){ int p,i,s,dp[2]; while (scanf("%d",&p)!=EOF) 阅读全文

posted @ 2013-03-04 18:13 Deller 阅读(132) 评论(0) 推荐(0)

PKU POJ 1958 Strange Towers of Hanoi DP
摘要:一维DP,不用进行递归。#include<iostream>using namespace std;int main(){ int n,k,min[13]; min[1]=1; min[2]=3; printf("1\n3\n"); for (n=3;n<=12;++n) { min[n]=0x7fffffff; for (k=1;k<n;++k) if(min[n]>(min[k]<<1)+(1<<(n-k))-1) min[n]=(min[k]<<1)+(1<<(n-k))-... 阅读全文

posted @ 2013-03-04 18:12 Deller 阅读(142) 评论(0) 推荐(0)

PKU POJ 1414 Life Line 搜索
摘要:题目很简单,就是在题目给点的区域划分下,判定哪些个区域和0相接,以及计算每个区域的节点数。搜索可以做,要注意搜索方向的设置。#include<iostream>using namespace std;int n,c,s[15][15];bool flag[15][15];int dir[6][2]={{-1,0},{-1,-1},{0,-1},{1,1},{0,1},{1,0}};inline bool judge(int x,int y){ return x>0&&y>0&&x<=n&&y<=x;}bool 阅读全文

posted @ 2013-03-04 18:09 Deller 阅读(170) 评论(0) 推荐(0)

导航