上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 61 下一页
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4240思路:题意真的有点难理解:在城市A->B之间通过所有路径一小时之内能通过最大的车辆(Maxflow)/所有边上通过最大车流量(cap)的那条叫做redundancy ratio。最小的redundancy ratio是前者最大的车流量的那一条(cap),问minimum redundancy ratio是多少。其实就是跑一次最大流,每当找到一条增广路时,记录此时的cap,然后取最大的就行了。 1 #include 2 #include 3 #include 4 #include 5 .. 阅读全文
posted @ 2013-09-11 17:50 ihge2k 阅读(559) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1513思路:n这么大,可以采用滚动数组,然后就是求原串和反串的LCS了。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 int dp[2][5555]; 8 char str1[5555],str2[5555]; 9 int n;10 11 int main()12 {13 while(~scanf("%d",&n)){14 scanf("%s",str1) 阅读全文
posted @ 2013-09-11 10:32 ihge2k 阅读(223) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1520思路:dp[u][0]表示不取u的最大价值,dp[u][1]表示取u的最大价值,于是有dp[u][0]+=max(dp[v][0],dp[v][1]),dp[u][1]+=dp[v][0](其中v是u的孩子)。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 #define MAXN 6060 8 9 int dp[MAXN][2];10 int n,ans;11 vector &g 阅读全文
posted @ 2013-09-10 23:20 ihge2k 阅读(274) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1561思路:dp[u][i]表示以u为根的树选了i个子节点。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 #define MAXN 222 8 9 int n,m;10 int dp[MAXN][MAXN];11 int val[MAXN];12 vector >G;13 14 void dfs(int u,int father)15 {16 for(int i=0;i=1;.. 阅读全文
posted @ 2013-09-10 22:41 ihge2k 阅读(232) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2809思路:简单的状压dp,看代码会更明白。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 struct State{ 8 int ati,def,hp,lev,exp; 9 }dp[1=S.lev*100){43 S.lev++;44 S.ati+=In_ati;45 S.d... 阅读全文
posted @ 2013-09-10 15:29 ihge2k 阅读(384) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2196思路:首先任意一次dfs求出树上最长直径的一个端点End,然后以该端点为起点再次dfs求出另一个端点,然后再次以求出的另一个端点为起点dfs,每次做dfs的时候都更新dist[](dist[u]表示u到树上任意节点的最远距离),可以证明树上任意某个节点到树上任意节点的最远距离的端点一定会是树上直径的两个端点之一。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 #define MAX 阅读全文
posted @ 2013-09-10 10:58 ihge2k 阅读(1588) 评论(1) 推荐(2) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4003思路:dp[i][j]表示以i为根选择j个机器人的最小花费,然后就是背包了:dp[u][i]=min(dp[u][i],dp[u][i-j]+dp[v][j]+j*w)(1 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 #define MAXN 10100 8 #define inf 1 >G;18 19 void dfs(int u,int father)20 {21 for(int i=0;. 阅读全文
posted @ 2013-09-09 21:29 ihge2k 阅读(227) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3899思路:num[u]表示u以及u的子树的队伍数的总和,dist[u]表示u到根节点的距离,dp[u]表示以u为根时的总花费。我们可以先做一次dfs算出树上所有点到根节点(1)的花费总和,然后同时计算出num[],然后就是又一次dfs算出以每个点为根的话费,这里有dp[v]=dp[u]+(sum-num[v])*w-num[v]*w(其中u是v的根)。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace 阅读全文
posted @ 2013-09-09 20:35 ihge2k 阅读(218) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4714思路:其实就是求树的分支数,然后就是分支数*2+1(要删边,加边变成直线最后在成环)。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 #define MAXN 1000100 8 #pragma comment(linker, "/STACK:1024000000,1024000000") 9 10 int n,ans;11 vector >G;12 13 阅读全文
posted @ 2013-09-08 21:18 ihge2k 阅读(341) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3905思路:dp[i][j]表示前i分钟,睡了j分钟收获的的最大价值,并记tmp_dp[i][j]为从i开始前的连续L分钟都是醒着的,并且睡了j分钟所能得到的最大价值,于是状态转移方程可以表示为:第 i 分钟睡dp[i][j]=dp[i-1][j-1];第 i 分钟醒着 dp[i][j]=max{dp[i][j],tmp_dp[i][j]}而tmp_dp[i][j]的转移方程为tmp_dp[i][j]=max(tmp_dp[i-1][j]+a[i],dp[i-l][j]+sum[i]-sum[i-l 阅读全文
posted @ 2013-09-08 20:19 ihge2k 阅读(252) 评论(0) 推荐(0) 编辑
上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 61 下一页