上一页 1 ··· 13 14 15 16 17
摘要: 记忆化搜索 1 #include<stdio.h> 2 #include<string.h> 3 int f[40][40][40]; 4 5 int ji(int a,int b,int c) 6 { 7 if(a<=0||b<=0||c<=0) 8 return 1; 9 10 if(f[a][b][c]>0)11 return f[a][b][c];12 13 else if(a>20||b>20||c>20)14 return f[a][b][c]=ji(20,20,20);15 16 else if(a<b&am 阅读全文
posted @ 2013-05-31 21:00 水门 阅读(283) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 #include 3 #include 4 char map[110][110],cpy[110][110]; 5 int vis[110][110]; 6 7 int dx[4]={0,0,1,-1}; 8 int dy[4]={1,-1,0,0}; 9 10 int tdx[8]={0,0,1,-1,1,-1,1,-1};11 int tdy[8]={1,-1,0,0,1,1,-1,-1};12 int n,i,j,cnt1,cnt2;13 14 void dfs(int i,int j)15 {16 int k;17 for(k=0; k=... 阅读全文
posted @ 2013-05-23 08:53 水门 阅读(109) 评论(0) 推荐(0) 编辑
摘要: 也是以前做的一个题,当时不会。bfs: 1 #include<stdio.h> 2 #include<string.h> 3 int a,b,c; 4 int vis[55][55][55],map[55][55][55]; 5 6 int dx[6]={0,0,0,0,-1,1}; 7 int dy[6]={0,0,1,-1,0,0}; 8 int dz[6]={1,-1,0,0,0,0}; 9 struct node10 {11 int x,y,z;12 int time1;13 }pos,npos,queue[55*55*55];14 15 int bfs()16 阅读全文
posted @ 2013-05-23 08:41 水门 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 以前做过的一个题,今天又做了一次。 1 #include 2 #include 3 #define maxn 2000 4 5 int u[maxn],v[maxn],bin[maxn]; 6 int find(int x) 7 { 8 return bin[x]==x?x:(bin[x]=find(bin[x])); 9 };10 11 int main()12 {13 int n,m,i,sum,x,y;14 while(~scanf("%d",&n)&&n)15 {16 sum=n-1;17 scanf("%d",& 阅读全文
posted @ 2013-05-23 08:36 水门 阅读(163) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1025参考博客:http://www.felix021.com/blog/read.php?1587最长不下降子序列,有一种DP+二分的求法最长递增子序列 O(NlogN)算法View Code 1 #include<stdio.h> 2 #include<string.h> 3 int a[500001],d[500001]; 4 int find(int a,int left,int rig) 5 { 6 int mid; 7 while(left<=rig) 8 阅读全文
posted @ 2013-05-11 21:21 水门 阅读(179) 评论(0) 推荐(0) 编辑
摘要: 类似于数塔的变形,只不过是每个数下面要取的是三个数的最大值,另外注意边界。第0秒 5第1秒 4 5 6第2秒 3 4 5 6 7第3秒 2 3 4 5 6 7 8第4秒 1 2 3 4 5 6 7 8 9第5秒 0 1 2 3 4 5 6 7 8 9 10第6秒 0 1 2 3 4 5 6 7 8 9 10第7秒 .................我的代码:View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 int dp[100001][12]; 5 int ma 阅读全文
posted @ 2013-04-30 09:58 水门 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 转自(http://www.cnblogs.com/tanhehe/articles/2998736.html)转自(http://www.cnblogs.com/vongang/archive/2011/12/23/2299729.html)在背包九讲里面将多重背包转化为01背包,并且进行时间优化... 阅读全文
posted @ 2013-04-29 09:54 水门 阅读(230) 评论(0) 推荐(0) 编辑
摘要: 卡特兰数又称卡塔兰数,是组合数学中一个常出现在各种计数问题中出现的数列。卡特兰数前几项为 : 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845, 35357670, 129644790, 477638700, 1767263190, 6564120420, 24466267020, 91482563640, 343059613650, 1289904147324, 4861946401452, ... 1 #include<stdio.h> 2 #incl 阅读全文
posted @ 2013-04-20 20:47 水门 阅读(120) 评论(0) 推荐(0) 编辑
摘要: http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=1500&cid=1147View Code 1 #include 2 #include 3 #include 4 5 struct node 6 { 7 int flag; 8 ... 阅读全文
posted @ 2013-04-07 21:02 水门 阅读(224) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2013-04-07 11:18 水门 阅读(179) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include "stdio.h" 2 int bin[1002]; 3 4 int findx(int x) 5 { 6 int r,j,i; 7 r = x; 8 while (bin[r] != r) 9 r = bin[r];10 i = x;11 while (i != r)12 {13 j = bin[i];14 bin[i] = r;15 i = j;16 }17 return r;18 }19 20 void merge(... 阅读全文
posted @ 2013-03-13 23:19 水门 阅读(142) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include <stdio.h> 2 #include<math.h> 3 int prime[1000000]; 4 int main() 5 { 6 int s,max; 7 while(scanf("%d",&max)!=EOF&&max!=0) 8 { 9 s=0;10 prime[0]=prime[1]=0;prime[2]=1;11 for(int i=3;i<max;i++)12 prime[i]=i%2==0?0:1;13 int t=(int)sqrt(max*1.0);.. 阅读全文
posted @ 2013-03-11 23:30 水门 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 普里姆算法(稠密图) 克鲁斯卡尔算法(稀疏图)1.prime 算法贪心 集合加点2.Kruskal算法并查集 加边http://acm.hdu.edu.cn/showproblem.php?pid=1233 思想是加 点,在边比较多的情况下,用prime。思路:先找 任意一点到其他的点的 最短距离... 阅读全文
posted @ 2013-03-01 14:50 水门 阅读(178) 评论(0) 推荐(0) 编辑
摘要: 一、单源最短路1、正权dijkstra2、任意权2、1 bellman-ford2、2 spfa二、任意点之间最短路floyd三、最短路的应用:差分约束系统参考模板http://www.toposort.com/blog/shortest-path.html贴一个新的最新的spfa模板: 1 #in... 阅读全文
posted @ 2013-02-27 11:21 水门 阅读(194) 评论(0) 推荐(0) 编辑
摘要: 题目:http://acm.hdu.edu.cn/showproblem.php?pid=2094//声明:该题不是我写的。 1 #include 2 #include 3 int nu,m,sum; 4 int map[1001][1001]; 5 int degree[1001]; 6... 阅读全文
posted @ 2013-02-26 20:21 水门 阅读(183) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 #include 3 int count,n,degree[505],map[505][505],vis[505],res[505]; 4 5 void topo(int x) 6 { 7 res[count] = x; 8 count++; 9 ... 阅读全文
posted @ 2013-02-26 10:52 水门 阅读(175) 评论(0) 推荐(0) 编辑
上一页 1 ··· 13 14 15 16 17