上一页 1 ··· 9 10 11 12 13 14 15 下一页
摘要: 1.差分约束差分约束系统是指形如AX<=B的一个不等式组,其中A的每行恰有一个1和一个-1,其它元素都是0这样的系统可以转化为图论的最短路模型,可以很巧妙的解决一些很难的题目这个链接里有一些关于差分约束系统的介绍差分约束系统,就是求出满足简单线性不等式组xj-xi<=bk的解。根据不等式,可以构造出约束图。可以证明,如果约束图中存在负权环,则无解,否则从约束图新构造的v0出发的单源最短路径就是问题的一组可行解。由于约束图中有负权,我们可以使用Bellman-Ford算法来解决最短路径问题。经典题目 :noi 99 01串 :zju1508应用范围:解决一些有不等关系的判断数列是否存 阅读全文
posted @ 2012-01-17 01:29 快乐. 阅读(323) 评论(0) 推荐(1) 编辑
摘要: http://poj.org/problem?id=1042被这个题虐的一塌糊涂啊,时间有两个世纪那么长有DP和贪心两种解法下面DP 状态转移方程 dp[i][j]=Max(dp[i][j],dp[i-1][j-ti[i]-k]), 但是因为memset(dp,-1,sizeof(dp)),所以写的时候是 dp[i+1][j+K+ti[i]]=Max(dp[i][j]+sum,dp[i+1][j+k+ti[i]);DP代码:#include<iostream>#include<string>#include<cstring>#include <cmat 阅读全文
posted @ 2012-01-16 17:57 快乐. 阅读(458) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1114完全背包问题两个代码 内外循环次序互换了代码一:46MS228K724 B#include<iostream>#include<string>#include<cstring>#include<cstdio>const int inf=6000005;using namespace std;int dp[10003],w[505],v[505];int main(){ int CASE,E,F,empty,n,i,j; scanf("%d&quo 阅读全文
posted @ 2011-12-24 10:15 快乐. 阅读(348) 评论(2) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2602本来想小复习一下,没想到居然被虐。。。开始用的二维,没有化,一直WA修改后的代码二维:#include<iostream>#include<cstring>#include<cstdio>using namespace std;__int64 dp[1001][1001];int W[1001],V[1001];int main(){ int CASE,i,j; int Sum,bag; cin>>CASE; while(CASE--) { cin> 阅读全文
posted @ 2011-12-21 00:33 快乐. 阅读(136) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1163数塔 cxl说因为这个题喜欢上DP的Description73 88 1 02 7 4 44 5 2 6 5(Figure 1)Figure 1 shows a number triangle. Write a program that calculates the highest sum of numbers passed on a route that starts at the top and ends somewhere on the base. Each step can go eit... 阅读全文
posted @ 2011-12-10 00:27 快乐. 阅读(171) 评论(0) 推荐(0) 编辑
摘要: http://www.tyut.edu.cn/kecheng1/site01/suanfayanshi/# 阅读全文
posted @ 2011-12-09 22:52 快乐. 阅读(127) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1469p门课 n个学生 n>p 一门课可以有多个学生选 一个学生可以不选 选一门或多门课 问是否可以找到p:p的匹配二分图的最大匹配代码:#include<iostream>#include<cstdio>#include<string>#include<cstring>using namespace std;bool map[102][302],visit[302];int link[302];int p,n;bool dfs(int u){ int i; for(i=1;i<= 阅读全文
posted @ 2011-12-04 13:00 快乐. 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 二分图最大匹配问题的匈牙利算法:#include<iostream>using namespace std;const int Max = 405;int n, m;//二分图中x和y中点的数目int link[Max];//link[x]记录当前与y节点相连的x的节点。bool map[Max][Max], vis[Max];//map[i][j]记录连接x和y的边,如果i和j之间有边则为1,否则为0。bool dfs(int u){//dfs实现,u表示现在在寻求匹配y的点x。for(int i = 1; i <= m; i ++)if(!vis[i] && 阅读全文
posted @ 2011-12-04 00:00 快乐. 阅读(186) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1274题意:奶牛只在一个或几个圈只中产奶,一个圈只可以有一头牛,问最多几头牛产奶典型的最大匹配 匈牙利算法代码:#include<iostream>#include<cstdio>#include<string>#include<cstring>using namespace std;bool map[202][202],visit[202];int link[202];int n,m;bool dfs(int u){ int i; for(i=1;i<=m;i++) { if(map[ 阅读全文
posted @ 2011-12-03 23:56 快乐. 阅读(222) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1242Angel所在的位置是a; Angel的朋友用r表示, Angel可能有多个朋友 ,也就是可能有多个r ; #表示墙 ;x表示警卫 ,可能会有多个警卫;Angel的朋友要进入a 只能上下左右的走, 每走一个格用一个单位时间,如果遇上警卫,杀掉警卫要花一个单位时间 问Angel能否救到angel,如果能 求最少的时间被这道题的有两个地方震了 1.有多个r 搜r到a有多条路 最后比较 但是倒过来想 从a搜到r就搜一条最佳路 2.涉及到一个杀警卫的时间,所以queue... 阅读全文
posted @ 2011-12-01 20:10 快乐. 阅读(277) 评论(0) 推荐(0) 编辑
上一页 1 ··· 9 10 11 12 13 14 15 下一页