摘要: 最小生成树,我是用邻接表+map存储姓名做的,点开1000就够了。View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <map>using namespace std;#define inf 0x3f3f3f3f#define maxn 1005#define maxl 25struct Edge{ int v, next; double w;}edge[maxn * maxn];int vis[maxn] 阅读全文
posted @ 2012-07-04 18:45 undefined2024 阅读(183) 评论(0) 推荐(0)
摘要: 状态压缩dp,数据弱,本程序时间效率O(12 * (2^24))View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 13#define mod 100000000int row, column;int filter[maxn];int f[maxn][1 << maxn];void input(){ scanf("%d%d", &r 阅读全文
posted @ 2012-07-04 16:01 undefined2024 阅读(524) 评论(0) 推荐(0)
摘要: 简单题View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 1005int n, t;int f[maxn];bool vis[maxn];int num;void input(){ scanf("%d%d", &n, &t); for (int i = 0; i < n; i++) scanf("%d", &a 阅读全文
posted @ 2012-07-04 15:09 undefined2024 阅读(256) 评论(0) 推荐(0)
摘要: 01背包View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;#define maxn 105#define maxm 15#define maxl 50#define maxt maxn * 1000struct Cloth{ int t, c;}cloth[maxn];int m, n;char color[maxm][maxl];bool f 阅读全文
posted @ 2012-07-04 14:28 undefined2024 阅读(326) 评论(0) 推荐(0)
摘要: 题意:给定一些奶牛,每个牛有s和f两个属性值,有正有负,要求选出一些牛,使得这些牛的两种属性的和的加和最大,且这些牛的两种属性分别求加和不能为负。分析:dp,开始想到dp[i][s][f],表示前i头牛能否实现属性和分别为s,f。空间和时间都不允许,要将f从状态中拿出來,让f的属性和作为所求的值。即变为d[i][s]=f的形式。表示用前i头牛构成s属性和为s的情况下f属性和最大为多少。状态转移从两种情况来,即用或者不用当前的牛。dp[i][j] = max(dp[i - 1][j - s[i]] + f[i], dp[i - 1][j])。在实际操作的时候可以将第一维去掉,进行空间上的优化。但 阅读全文
posted @ 2012-07-04 13:45 undefined2024 阅读(1949) 评论(0) 推荐(2)
摘要: floyd变形View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 306#define inf 0x3f3f3f3fint n, m, t;int map[maxn][maxn];void input(){ scanf("%d%d%d", &n, &m, &t); for (int i = 0; i < n; i++) f 阅读全文
posted @ 2012-07-04 10:51 undefined2024 阅读(178) 评论(0) 推荐(0)
摘要: 题意:给定一个矩阵,其中有一些地方有水,用一些长度任意,宽度为1的木板盖住这些有水的地方,问至少需要几块板子。分析:二分图最小点集覆盖。二分图建图方法如下,把每段连续的横向的水洼看成是一个X集合中的点,每段连续的纵向的水洼看成是Y集合中的点。矩阵每个有水单元看成是一个边,它连接了它所在的横向水洼在X集合中对应的点和它所在的纵向水洼在Y集合中对应的点。(对于一段连续的水洼,如果要铺木板,一定要铺得尽量长)这样最小点集覆盖的意义就变成了,矩阵中的每个有水的单元(二分图中的每条边)所在的横向和纵向的水洼(在X集合和Y集合中的两个端点)至少有一个被覆盖。求至少需要选几个点。View Code #inc 阅读全文
posted @ 2012-07-04 10:27 undefined2024 阅读(1136) 评论(2) 推荐(2)
摘要: 题意:约瑟夫问题变形,给定人数和最后存活的编号,问杀人间隔最少是多少。分析:从小到大枚举杀人间隔,然后用解约瑟夫问题的方法,求最后存活的人,如果恰好是要求的那个,则输出结果。View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;int n;int last(int n, int m){ int ret = 0; for (int i = 2; i <= n; i++) ret = (ret + 阅读全文
posted @ 2012-07-04 09:29 undefined2024 阅读(139) 评论(0) 推荐(0)