andre_joy

导航

上一页 1 2 3 4 5 6 7 8 9 10 ··· 15 下一页

2012年8月20日

hdu 1428

摘要: 地址:http://acm.hdu.edu.cn/showproblem.php?pid=1428题意:问最短路径有多少条。mark:首先bfs是用来确定每个点到终点的最短路径。dfs来确定有多少条相同的最短路径。代码:#include <stdio.h>#include <string.h>#include <stdlib.h>#include <queue>#define LL long longusing namespace std;typedef struct{ int a,b;}qq;const int N = 60;const int 阅读全文

posted @ 2012-08-20 18:01 andre_joy 阅读(175) 评论(0) 推荐(0) 编辑

2012年8月19日

hdu 1208

摘要: 地址:http://acm.hdu.edu.cn/showproblem.php?pid=1208题意:走迷宫,每个格子里面数字代表与下一个格子间隔是几,求有多少种走法到n。mark:记忆化搜索。本来觉得直接暴力搜索可过,结果tle了。dp[i][j]存放该格子有多少总走法。代码:#include <stdio.h>#include <string.h>#include <stdlib.h>int n;char a[40][40];int s[40][40];long long dp[40][40];int tab[2][2] = {1, 0, 0, 1}; 阅读全文

posted @ 2012-08-19 20:06 andre_joy 阅读(238) 评论(0) 推荐(0) 编辑

hdu 1078

摘要: 地址:http://acm.hdu.edu.cn/showproblem.php?pid=1078题意:老鼠偷吃,有n*n的方阵,每个格子里面放着一定数目的粮食,老鼠每次只能水平或竖直最多走k步,每次必须走食物比当前多的格子,问最多吃多少食物。mark:记忆化搜索。代码:#include <stdio.h>#include <string.h>#include <stdlib.h>int n,m,max1;int s[110][110],dp[110][110];int tab[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};int m 阅读全文

posted @ 2012-08-19 16:14 andre_joy 阅读(750) 评论(0) 推荐(0) 编辑

hdu 1074

摘要: 地址:http://acm.hdu.edu.cn/showproblem.php?pid=1074题意:有很多作业,没有在规定时间内完成要扣分,一天一分,求最小扣分!mark:wa了两次,傻了。。把题意理解错了。是超过期限一天就扣一分!!! 状态压缩dp。dp[i]代表第i个状态的最小罚时,由于本题要输出顺序,所以给dp加上了一个变量,是该状态是由哪个状态来的。代码:#include <stdio.h>#include <string.h>#include <stdlib.h>const int M = (1 << 15);typedef str 阅读全文

posted @ 2012-08-19 13:24 andre_joy 阅读(156) 评论(0) 推荐(0) 编辑

2012年8月17日

hdu 4374

摘要: 地址:http://acm.hdu.edu.cn/showproblem.php?pid=4374题意:有n层,每层有m个模块,每个模块都有对应的权值,每层只能沿一个方向走,每层最多走t步,求最大权值的和。mark:单调队列,dp[i][j]代表第i层,第j块最大的权值。 首先每次求得dp[i][j]后,先向下走给dp[i+1][j]一个初始值,即dp[i+1][j] = dp[i][j]+w[i+1][j],(w[i][j]表示第i层第j块的权值。) 然后单调队列,左边右边各弄一次,去最大值。代码:#include <stdio.h>#include <string.h&g 阅读全文

posted @ 2012-08-17 16:30 andre_joy 阅读(227) 评论(0) 推荐(0) 编辑

2012年8月14日

hdu 4362

摘要: 地址:http://acm.hdu.edu.cn/showproblem.php?pid=4362题意:挖宝石,宝石都出现在一条直线上,每次出现n个宝石,只能挖其中一个,剩下消失。总共有m次机会。精力消耗有路程的消耗和挖宝石的时候消耗,求最小消耗。mark:dp。维护两个最值,把问题分成从位置大于和小于目前位置两种情况讨论。dp[i][j]代表第i段时间挖第j个石头消耗最小。 首先只考虑位置比目前小的情况,dp[i][j] = min{dp[i-1][k]+p[i][j]-p[i-1][k]+e[i][j]} = min{dp[i-1][k]-p[i-1][k]}+p[i][j]+e[i].. 阅读全文

posted @ 2012-08-14 19:46 andre_joy 阅读(261) 评论(8) 推荐(0) 编辑

2012年8月9日

hdu 4340

摘要: 地址:http://acm.hdu.edu.cn/showproblem.php?pid=4340题意:两个人抢劫一个城市,每个人抢前一个城市相邻的城市的时候只用花费1/2的时间,求最短时间。mark:树状dp。dp[i][j][k]代表第i个城市由第j个人抢劫,第i个城市所属子树需要完全时间的个数。代码:#include <stdio.h>#include <string.h>#include <stdlib.h>const int M = 105;const int N = 10000000;int n,s[2][M];int dp[M][2][2];b 阅读全文

posted @ 2012-08-09 18:44 andre_joy 阅读(229) 评论(0) 推荐(0) 编辑

2012年8月8日

hdu 3415

摘要: 地址:http://acm.hdu.edu.cn/showproblem.php?pid=3415题意:给一个序列,规定区间大小,求和最大的子序列。mark:单调队列。。。经验不足,做了很久。代码:#include <stdio.h>#include <string.h>const int M = 100010;int sum[2*M], a[2*M], q[2*M];int main(){// freopen("in.txt", "r", stdin);// freopen("out.txt", " 阅读全文

posted @ 2012-08-08 17:27 andre_joy 阅读(241) 评论(0) 推荐(0) 编辑

2012年8月6日

hdu 3401

摘要: 地址:http://acm.hdu.edu.cn/showproblem.php?pid=3401题意:炒股……规定每天最多买进多少,卖出多少,并且每次炒股后隔w天才能再次炒股,问最大收益。mark:首先想到最朴素的dp。dp[i][j]代表第i天有j股会带来最大收益。 则dp[i][j] = max(dp[i-1][j], dp[r][k]-(j-k)ap[i], dp[r][k]+(k-j)bp[i]); 复杂度是O(T*T*Maxp*Maxp)。 首先想到第一步优化,前面式子r范围是0~i-w-1,怎么优化呢,因为dp[i][j]至少为dp[i-1][j],那么dp[i-w-1... 阅读全文

posted @ 2012-08-06 16:17 andre_joy 阅读(241) 评论(0) 推荐(0) 编辑

2012年8月4日

hdu 3001

摘要: 地址:http://acm.hdu.edu.cn/showproblem.php?pid=3001题意:n(最多10)个城市,可以从任意城市出发,每个城市最多走两次,问最短路径。mark:TSP问题,由于最多走两次,所以是三进制状态压缩DP,第一次写,很艰难。 可以转换成任意进制的~代码:#include <stdio.h>#include <string.h>#include <stdlib.h>const int M = 67149;const int inf = 0x3f3f3f3f;int dp[70000][15];int adj[15][15]; 阅读全文

posted @ 2012-08-04 17:46 andre_joy 阅读(514) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 7 8 9 10 ··· 15 下一页