上一页 1 ··· 49 50 51 52 53 54 55 56 57 ··· 61 下一页
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2181题意:就是让你求哈密尔顿环,并输出所有可能的路径。思路:用一个数组path[N]来保存路径,然后暴搜就可以了,不过回退的时候,visited[i]应该置为0。View Code 1 #include<iostream> 2 const int N=20; 3 using namespace std; 4 int map[N+1][N+1]; 5 int visited[N+1]; 6 int path[N+1]; 7 int m,_count=1; 8 9 void Initiat 阅读全文
posted @ 2013-03-18 21:20 ihge2k 阅读(789) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2117题意:问1/n的小数点后第m位是多少。高精度除法。直接上代码了:View Code 1 #include 2 using namespace std; 3 4 int solve(int n,int m){ 5 int divided=1,res=0; 6 for(int i=0;i<=m;i++){ 7 res=divided/n; 8 divided=10*(divided%n); 9 }10 return res;11 ... 阅读全文
posted @ 2013-03-18 20:32 ihge2k 阅读(214) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2119题意很好理解,就是每次可以删除一行或者一列数,问最少几次可以把所有的1都变成0,也就是都删完。用二分图表示,行代表二分图的一部分,列代表二分图的一部分,map[i][j]==1代表连一条边,这样就转化为求最小顶点覆盖,即求二分图的最大匹配(边数最多的匹配,即把尽可能多的边与某一个顶点相关联,这样选择全部的边所需要的最少顶点就是最小顶点覆盖)。此外,二分图还有最小路径覆盖,意思是用最少的边把图中所有的顶点都遍历到(最小路径覆盖 = 顶点数 - 最大匹配)。View Code 1 #includ. 阅读全文
posted @ 2013-03-18 19:03 ihge2k 阅读(288) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2100一道水题,orz,WA了3次,坑爹啊。。。。不说了,就是一个26进制加分,结果应该是要写成最简洁形式的。。。View Code 1 #include 2 #include 3 #include 4 const int N=222; 5 using namespace std; 6 char str1[N],str2[N],str[N]; 7 8 int main(){ 9 while(~scanf("%s",str1)){10 scanf("%s",st 阅读全文
posted @ 2013-03-17 10:55 ihge2k 阅读(363) 评论(0) 推荐(0) 编辑
摘要: 欧拉回路:简单来说,就是经过图G的每条边一次且仅一次,回到出发点的路径就叫欧拉回路;我就直接上模板了。。。。View Code 1 #include<iostream> 2 #include<stack> 3 const int MAXN=111; 4 using namespace std; 5 6 stack<int>S; 7 int edge[MAXN][MAXN]; 8 int n,m; 9 10 void dfs(int x){11 S.push(x);12 for(int i=1;i<=n;i++){13 if(edge[x][i]> 阅读全文
posted @ 2013-03-16 11:46 ihge2k 阅读(3777) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3127对于一个小矩形,有两种切割方式(上下):1、在xx上切x,在yy上切y;2、在xx上切y,在yy上切x故有:1、在xx上切x,在yy上切y;dp[i][j]=max(dp[i][j],max(dp[x][j-y]+dp[i-x][j],dp[i][j-y]+dp[i-x][y])+value);2、在xx上切y,在yy上切xdp[i][j]=max(dp[i][j],max(dp[y][j-x]+dp[i-y][j],dp[i][j-x]+dp[i-y][x])+value);其中dp[i][ 阅读全文
posted @ 2013-03-16 09:26 ihge2k 阅读(391) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1559思路:感觉就是1081这题差不多,但就是加了一个限制条件。。。View Code 1 #include<iostream> 2 #include<algorithm> 3 const int N=1010; 4 using namespace std; 5 6 int map[N][N]; 7 8 int main(){ 9 int _case;10 scanf("%d",&_case);11 while(_case--){12 int m, 阅读全文
posted @ 2013-03-15 19:15 ihge2k 阅读(421) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1081思路:其实就是化二维为一维,可以把有相同行数的每一列的最大值求出来就可以了,每次都更新就行了。。。View Code 1 #include<iostream> 2 const int N=110; 3 const int inf=1000000000; 4 using namespace std; 5 6 int num[N][N]; 7 int dp[N]; 8 9 int main(){10 int n;11 while(~scanf("%d",&n 阅读全文
posted @ 2013-03-15 11:51 ihge2k 阅读(584) 评论(0) 推荐(1) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251一开始我是直接用STL做的,唉。。。没有经验那。。。orz...然后毫无疑问地超时了。。。看别人blog说是字典树,说实话,第一次听到这个。。。就立马学了一下。。发现挺简单的。。。嘻嘻。。。View Code 1 #include 2 #include 3 const int N=26; 4 using namespace std; 5 struct Tire{ 6 int v; 7 Tire *next[N]; 8 }; 9 Tire *root;10 11 //创建字典树... 阅读全文
posted @ 2013-03-14 20:05 ihge2k 阅读(277) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1261思路:公式很好推,就是(n1+n2+n3+...nn)!/(n1!+n2!+...+nn!);然后毫无疑问要用到大数计算...发现用string,vector还是挺方便的。。。View Code 1 #include<iostream> 2 #include<vector> 3 #include<string> 4 #include<algorithm> 5 using namespace std; 6 int num[27]; 7 vector 阅读全文
posted @ 2013-03-14 16:21 ihge2k 阅读(581) 评论(1) 推荐(0) 编辑
上一页 1 ··· 49 50 51 52 53 54 55 56 57 ··· 61 下一页