上一页 1 ··· 14 15 16 17 18 19 20 21 22 ··· 61 下一页
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4294思路:题目的意思是说,给你n,k,则求出n的正整数倍数,使得这个数字在k进制下表示的时候需要的不同数字最小。首先明确最多的不同数字需要2种,证明如下a,aa,aaa,aaaa,......找出n个连续的,那么中间至少有两个modn的值是相等的,那么这两个数字相减,得到aaa...000肯定能被n整除,因此可以bfs搜索只含有1个数字的和只含有2个数字的。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using n... 阅读全文
posted @ 2013-09-03 22:08 ihge2k 阅读(265) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=1088思路:简单记忆化搜索,dfs深搜的条件为map[xx][yy] 2 #include 3 #include 4 #include 5 using namespace std; 6 7 int dp[111][111]; 8 int map[111][111]; 9 int n,m,ans;10 int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};11 12 int dfs(int x,int y)13 {14 if(dp[x][y])return dp[x][y];15 in... 阅读全文
posted @ 2013-09-03 19:44 ihge2k 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=2531思路:由于N才20,可以dfs爆搞,枚举所有的情况,复杂度为2^(n)。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 int map[22][22]; 8 int belong[22]; 9 int n,ans;10 11 void dfs(int pos,int sum)12 {13 if(pos==n+1){14 ans=max(ans,sum);15 return ;16 ... 阅读全文
posted @ 2013-09-02 19:14 ihge2k 阅读(498) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=1129思路:根据图的四色定理,最多四种颜色就能满足题意,使得相邻的两部分颜色不同。而最多又只有26个点,因此直接dfs即可。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 bool map[33][33]; 8 int mark[33]; 9 char str[33];10 int n,ans;11 12 bool Judge(int x,int color)13 {14 for(int i=0;i<n;i++){15 ... 阅读全文
posted @ 2013-09-01 20:42 ihge2k 阅读(842) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=3414思路:bfs简单应用,增对瓶A或者瓶B进行分析就可以了,一共6种状态。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 8 struct Node{ 9 int a,b,step; 10 char str[111][111]; 11 }; 12 13 int A,B,C; 14 bool mark[111][111]; 15 bool bfs() 16 { 17 mem... 阅读全文
posted @ 2013-09-01 10:27 ihge2k 阅读(815) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=2662思路:首先路径的选择,如果B点到终点的距离比A点到终点的最短距离短,那么就从A走到B,换句话说,就是每次都是择优选择更靠近终点的点。于是我们可以从终点2跑一次Dijkstra,求出每个点到终点的最短距离,然后就是从起点1开始记忆化搜索,如果满足上面条件的,就dfs. 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 #define MAXN 1111 9 #define inf 1 >G; 阅读全文
posted @ 2013-09-01 09:16 ihge2k 阅读(257) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3681思路:机器人从出发点出发要求走过所有的Y,因为点很少,所以就能想到经典的TSP问题。首先bfs预处理出‘Y',’F','G'之间的最短距离,由于G点可以充电,到达G点就把当前能量更新为电池容量然后继续走。因为每个G点只能充一次电,这就好像TSP中的每个点只能走一次一样,然后就是二分答案了,用状压DP判定当前电池容量的情况下是否能符合条件。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using 阅读全文
posted @ 2013-08-31 11:14 ihge2k 阅读(429) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4539思路:跟poj1185简直就是如出一辙! 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 int row[111]; 8 int dp[111][222][222]; 9 int s[10){17 cnt++;18 x=x&(x-1);19 }20 return cnt;21 }22 23 int main()24 {25 while(~sca... 阅读全文
posted @ 2013-08-30 20:39 ihge2k 阅读(231) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=1185思路:状态压缩经典题目,dp[i][j][k]表示第i行状态为j,(i-1)行状态为k时最多可以放置的士兵个数,于是我们可以得到递推方程:dp[i][j][k]=max(dp[i][j][k],dp[i-1][k][l]+num[j]);(其中num[j]为该状态下可以放置的士兵的个数。至于具体怎么分析,这位大牛讲的很清楚:http://www.cnblogs.com/scau20110726/archive/2013/02/27/2935256.html 1 #include 2 #include 3 #include 4 阅读全文
posted @ 2013-08-30 19:52 ihge2k 阅读(226) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2167思路:经典的状压dp题,前后,上下,对角8个位置不能取,状态压缩枚举即可所有情况,递推关系是为dp[i][j]=max(dp[i][j],dp[i-1][k]+sum[i][j]),具体的含义见code: 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 int s[1>1))continue;34 if(s[j]&(s[k]<<1))continue;35 ... 阅读全文
posted @ 2013-08-30 16:53 ihge2k 阅读(313) 评论(0) 推荐(0) 编辑
上一页 1 ··· 14 15 16 17 18 19 20 21 22 ··· 61 下一页