摘要:
思路:先dfs一下,找出1,n间的路径长度和价值,回溯时将该路径长度和价值清零。那么对剩下的图就可以直接树形dp求解了。#include#include#include#include#define inf 100000000#define Maxn 110using namespace std;int vi[Maxn],head[Maxn],dp[Maxn][510],e,n,T,a[Maxn],len,sum;struct Edge{ int u,v,next,val;}edge[Maxn*2];void init(){ memset(vi,0,sizeof(vi)); ... 阅读全文
摘要:
思路:先求以1为根时,每个节点到子节点的最大长度。然后再次从1进入进行更新。#include#include#include#include#include#define Maxn 20010#define inf 0x7fffffffusing namespace std;int vi[Maxn],si[Maxn],n,road[Maxn],Max[Maxn],lMax[Maxn],head[Maxn],e;struct Edge{ int u,v,val,next;}edge[Maxn*2];void init(){ memset(vi,0,sizeof(vi)); me... 阅读全文
摘要:
思路:裸的划分树#include#include#include#include#include#define Maxn 100010#define lson(x) x>1)using namespace std;int val[20][Maxn],toLeft[20][Maxn],sorted[Maxn];struct Tree{ int l,r;}tree[Maxn*4];void BuildTree(int l,int r,int dep,int po){ tree[po].l=l,tree[po].r=r; if(l==r) return ; in... 阅读全文
摘要:
思路:裸的划分树#include#include#include#include#include#include#define Maxn 100010#define inf 0x7fffffff#define lson(x) (x>1)using namespace std;struct Tree{ int l,r;}tree[Maxn*4];int sorted[Maxn];int val[20][Maxn],toLeft[20][Maxn];void BuildTree(int l,int r,int dep,int po){ tree[po].l=l,tree[po].r=r... 阅读全文
摘要:
思路:用Sum[dep][i]记录从tree[po].l到i中进入左子树的和。#include#include#include#include#include#include#define Maxn 100010#define inf 0x7fffffff#define lowbit(x) (x&(-x))#define lson(x) (x>1)using namespace std;struct Tree{ int l,r;}tree[Maxn*4];__int64 Sum[20][Maxn],sum[Maxn];__int64 lnum,lsum;int sorted[Ma 阅读全文
摘要:
思路:二分枚举区间第k大。用划分树查找是否符合要求的高度。#include#include#include#include#include#define Maxn 100010#define lson(x) x>1)using namespace std;int val[20][Maxn],toLeft[20][Maxn],sorted[Maxn];struct Tree{ int l,r;}tree[Maxn*4];void BuildTree(int l,int r,int dep,int po){ tree[po].l=l,tree[po].r=r; if(l==r) ... 阅读全文
摘要:
思路:直接搜索#include#include#include#includeusing namespace std;int belong[5010],num[5010],n;int dfs(int s,int pre,int cur){ int i,j; if(cur==n/2) return 1; for(i=s;ipre) { belong[j]=1; if(dfs(s+1,j,cur+1)) return 1; ... 阅读全文