2013年7月29日

poj2533

摘要: 1 /*解题思路请看给分类的最长递增子序列算法解析那篇文章*/ 2 #include 3 #include 4 int find(int *c,int len,int n) 5 { 6 int l=0,r=len; 7 while(ln) r=mid-1;12 else return mid;13 }14 return l;15 }16 int main()17 {18 int i,j,n;19 int a[1005], c[1005],len;20 while(scanf("%d",&n)!=EOF)21 {2... 阅读全文

posted @ 2013-07-29 22:02 ok_boy 阅读(146) 评论(0) 推荐(0)

最长上升子序列算法解析

摘要: 1 LIS什么是最长递增子序列呢? 2 问题描述如下: 3 设L=是n个不同的实数的序列,L的递增子序列是这样一个子序列Lin=, 4 其中k1 16 using namespace std; 17 int main() 18 { 19 int i,j,n,a[100],b[100],max; 20 while(cin>>n) 21 { 22 for(i=0;i>a[i]; 24 b[0]=1;//初始化,以a[0]结尾的最长递增子序列长度为1 25 f... 阅读全文

posted @ 2013-07-29 21:51 ok_boy 阅读(413) 评论(0) 推荐(0)

poj2092

摘要: 1 /*水题,算每个号码处出现的次数*/ 2 #include 3 #include 4 #include 5 using namespace std; 6 const int maxn=10000+10; 7 struct point 8 { 9 int num,index;10 }p[maxn];11 int cmp(const point a,const point b)12 {13 if(a.num==b.num) return a.indexb.num;15 }16 int hash[maxn];17 int main()18 {19 int i,j,n,m... 阅读全文

posted @ 2013-07-29 20:25 ok_boy 阅读(314) 评论(0) 推荐(0)

最长公共子序列算法解析

摘要: /*转自网上总结*/一、最长公共子序列(Longest Common Subsequence:LCS)设有两个序列A[1...m]和B[1...n],分别对A和B进行划分子序列A[1] A[1..2] A[1..3] ... A[1..m]B[1] B[1..2] B[1..3] ... B[1..n]依次求出A中的每个子序列(从A[1]开始)与B中每个子序列的最长公共子序列,并记录在数组C[m][n]中,C[i][j]表示A[1..i]和B[1..j]的最长公共子序列的长度。递推公式如下:①C[i][j]=0 i=0 or j=0②C[i][j]=C[i-1][j-1]+1 i!=0 and 阅读全文

posted @ 2013-07-29 18:14 ok_boy 阅读(1187) 评论(0) 推荐(0)

poj1159

摘要: 1 /*/所要插入的个数是n-输入的序列和他逆序列的最长公共子串长度**/ 2 3 #include 4 #include 5 char a[5010],b[5010]; 6 short int dp[5010][5010];//用int会爆内存 7 int LCS(int n,int m) 8 { 9 int i,j;10 for(i=1;i=dp[i][j-1])19 {20 dp[i][j]=dp[i-1][j];21 // dir[i][j]=0;22 }2... 阅读全文

posted @ 2013-07-29 18:12 ok_boy 阅读(216) 评论(0) 推荐(0)

poj1458

摘要: 1 /* 最长公共子序列*/ 2 #include 3 #include 4 #include 5 using namespace std; 6 int dp[1000][1000],dir[1000][1000]; 7 char a[1000],b[1000]; 8 int LCS(int n,int m) 9 {10 int i,j;11 for(i=1;i=dp[i][j-1])20 {21 dp[i][j]=dp[i-1][j];22 dir[i][j]=0;23 ... 阅读全文

posted @ 2013-07-29 18:11 ok_boy 阅读(213) 评论(0) 推荐(0)

poj2250

摘要: 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 char a[1010][35],b[1010][35]; 8 int dir[1000][1000],dp[1000][1000]; 9 int LCS(int n,int m)10 {11 int i,j;12 for(i=1;i=dp[i][j-1])21 {22 dp[i][j]=dp[i-1][j];23 dir[i][j... 阅读全文

posted @ 2013-07-29 18:10 ok_boy 阅读(182) 评论(0) 推荐(0)

poj1068

摘要: 1 /*读懂题意:pi表示右括号前面有几个左括号, 2 wi表示与右括号配对的左括号与该右括号之间有几个左括号, 3 包括配对的,已经配对过的左括号不能再与右括号配对 4 解法:还原原来的字符串*/ 5 #include 6 #include 7 #include 8 using namespace std; 9 int main()10 {11 int i,j,k,n,m;12 int a[505],b[505],c[505];13 int t;14 scanf("%d",&t);15 while(t--)16 {17 sca... 阅读全文

posted @ 2013-07-29 18:09 ok_boy 阅读(244) 评论(0) 推荐(0)

poj1694

摘要: 1 /*给出一棵树的描述 2 第一行输入t,代表案例的个数 3 第二行一个n代表这棵树有n个节点 4 接下来n行第一个数是节点的编号,根节点编号为1,然后第二个数是节点的个数,如果为0那就没子节点,否则输入节点的 5 编号 6 方法:递归+排序 7 先求出根节点的r个子节点需要的最小石头数,然后按大到小排序r1,r2,r3..rr,另结果result初值为最大的那个 8 r1,然后剩下为remain=result-1,然后将remain从r2遍历到rr,如果都比remainxiao说明剩下的可以满足,否则结果 9 result+=ri-remain,remain=ri-1;,遍历r个数以后就. 阅读全文

posted @ 2013-07-29 18:08 ok_boy 阅读(306) 评论(0) 推荐(0)

poj2993

摘要: #include#include#includeusing namespace std;struct point { int i,j; int num; char c;}p[1000];int find(char n){ if(n=='a') return 2; if(n=='b') return 6; if(n=='c') return 10; if(n=='d') return 14; if(n=='e') return 18; if(n=='f') return 22; if(n==' 阅读全文

posted @ 2013-07-29 18:05 ok_boy 阅读(152) 评论(0) 推荐(0)

poj2996

摘要: 1 /*排序函数要写对,优先级:K,Q,R,B,N,P 2 白色的:如果优先级一样,那么按照行数大的优先,如果行数一样,那么列数小的优先 3 黑色的:如果优先级一样,那么按照行数小的优先,如果行数一样,那么列数小的优先 4 第一个在左下脚,向上数*/ 5 #include 6 #include 7 #include 8 using namespace std; 9 struct point 10 { 11 int i,j; 12 char c; 13 int num; 14 }p[1000]; 15 int cmp(const point a,con... 阅读全文

posted @ 2013-07-29 18:04 ok_boy 阅读(243) 评论(0) 推荐(0)

poj3125

摘要: /*水题,模拟排队*/#include#include#includeusing namespace std;const int maxn=10000;struct point{int index;int i;}p[maxn];int main(){int i,j,k,n,m;int t;scanf("%d",&t);while(t--){scanf("%d%d",&n,&m);for(i=0;i<=10000;i++){p[i].index=0;p[i].i=0;}for(i=0;i<n;i++){scanf(&qu 阅读全文

posted @ 2013-07-29 18:02 ok_boy 阅读(203) 评论(0) 推荐(0)

导航