随笔分类 - DP——树形
摘要:题目链接:http://acm.bupt.edu.cn/onlinejudge/newoj/showProblem/show_problem.php?problem_id=1267/**算法分析:*/#include#include#include#include#include#include#include#include#include#include#include#include#define MAXN 505#define PI acos(-1.0)#define INF 0x3f3f3f3f#define REP(i,n) for(int i=0; i>>"
阅读全文
摘要:题目链接:http://codeforces.com/problemset/problem/337/D参考博客:http://www.cnblogs.com/chanme/p/3265913题目大意:给你一个n个点的无向树。任意两点的距离为中间经过的边数。现在某个点上有本魔法书,这本书对与这个点距离小于等于d的点有影响。给你收集到的m个受影响的点(信息不一定全对)。要你判断有多少个点可能放魔法书。算法思路:我参考别人的想法,自己开始怎么也想不出好的算法,n也太大。这题用树形dp,两遍dfs来统计出每一个点到所有这个m个受影响点的距离的最大值。只要这个最大值#include#include#in
阅读全文
摘要:题目链接:http://codeforces.com/problemset/problem/219/D#include#include#include#include#include#includeusing namespace std;const int maxn = 2*1e5+100;int dp[maxn]; //dp[i]表示以i为根遍历全部的点的最小的权值。struct Edge{ int u,v,w; int next; Edge(int u=0,int v=0,int w=0,int next=0): u(u), v(v), w(w), next(next)...
阅读全文
摘要:#include#include#include#include#includeusing namespace std;const int maxn = 100;int dp[maxn][maxn]; //dp[i][j]表示以i为根,保留j个点的最大权值。int N,Q;int G[maxn][maxn];int num[maxn]; //以i为根的树的节点个数。//这里处理的时候要注意可以把边的权值压倒儿子节点。void dfs(int u,int fa){ num[u] = 1; for(int v=1;v0;i--){ //相对于下面的V -> 0 ...
阅读全文
摘要:题目链接:http://lightoj.com/volume_showproblem.php?problem=1032#include #include #include #include #include #include #include using namespace std;const int maxn = 33;const int INF = 0x3f3f3f;long long dp[maxn];int sum[9] = {0,0,0,1,1,1,2,4,4};long long int N;inline long long res(int i){ return (1>T..
阅读全文
摘要:题目链接:http://poj.org/problem?id=1192#include#include#include#include#includeusing namespace std;const int maxn = 1005;const int INF = 0x3f3f3f;int dp[maxn];vector G[maxn];int W[maxn];int N;struct Point{ int x,y;}P[maxn];int ans;void dfs(int u,int fa){ dp[u] = W[u]; for(int i=0;i<G[u].size();...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1520#include#include#include#include#include#include#includeusing namespace std;const int maxn = 6050;const int maxe = 10000;const int INF = 0x3f3f3f;struct Edge{ int u,v; int next; void assign(int u_,int v_,int next_){ u = u_; v = v_...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3409参考博客:http://www.cnblogs.com/woaishizhan/p/3189813.html#include#include#include#include#include#include#includeusing namespace std;const int maxn = 205;const int maxe = 20500;const int INF = 0x3f3f3f;struct Edge{ int u,v,w; int next; void as...
阅读全文