上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 16 下一页
摘要: http://poj.org/problem?id=1463DP,树状DP,或二分图匹配 1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #include <vector> 5 using namespace std; 6 7 const int N = 1505; 8 9 int pre[N];10 bool flag[N];11 vector<int> map[N];12 int n;13 14 int find(int x)15 {16 int 阅读全文
posted @ 2013-05-23 19:52 Yuan1991 阅读(154) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=1947DP,树状DP一棵节点为N的树,去掉最少的边,满足剩下树中,有一棵树的节点数为P还要用分组背包优化,分组背包自己想的思路,写的比较难看。。。dp[i][j]:表示以节点i为根的树,如果想要保证有j个节点,至少要去掉的边数对于每组dp[i],只能选一种j,如果不选这一组,也要多消耗1的费用叶子节点初始化:dp[i] = {0, 1, 正无穷, 正无穷.......};之后看了一下背包九讲:还可以把每个节点看成一个物品,那就成了背包九讲中的“泛化物品”背包,之前没理解泛化的意思,现在有了一个大概的理解了安背包九讲的定义,这题可以简述成:有 阅读全文
posted @ 2013-05-23 17:55 Yuan1991 阅读(145) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=1848DP, 树状DP一个节点形成环的过程中只有3种状态,0:有0条边连着这个点1:有1条边连着这个点2:有2条边连着这个点转移还可以再优化,不过不太好写,直接上3层循环。。。代码中inf的定义:至少要添无穷多个边,才可以满足要求 ---等价于---> 添多少都没用 1 #include <stdio.h> 2 #include <vector> 3 #define N 123 4 5 using namespace std; 6 7 vector<int> a[N]; 8 int mark[N], 阅读全文
posted @ 2013-05-22 16:58 Yuan1991 阅读(143) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=1056Trie有一些字符串,判断是否:这些字符串之间都不是彼此的前缀 1 #include <stdio.h> 2 #include <string.h> 3 4 const int CHARSET = 2, BASE = '1', MAX_NODE = 1001; 5 6 int tot, root, child[MAX_NODE][CHARSET]; 7 bool flag[MAX_NODE]; 8 9 void init()10 {11 memset(child, 0, sizeof(child 阅读全文
posted @ 2013-05-18 20:56 Yuan1991 阅读(166) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=1192题目大意:有一棵树,节点有整型的权值,如果定义,树中所有节点的权值和为树的权值,题目是求权值最大的子树 1 #include <stdio.h> 2 #include <string.h> 3 #include <vector> 4 5 #define N 1010 6 7 using namespace std; 8 9 int n, x[N], y[N], c[N], mark[N] = {0};10 vector<int> a[N];11 12 int abs(int x)13 { 阅读全文
posted @ 2013-03-27 22:47 Yuan1991 阅读(234) 评论(0) 推荐(0)
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 16 下一页