传送门

设$f[i][j][k]$表示对于第$i$个点,向父节点贡献$j$个已合成的装备,花费了$k$的代价,最多获得的力量值。

单纯的$f[i][j][k]$是很难转移的,主要原因是无法维护和其他儿子的关系。所以对于每个节点再搞一个$g[i][j]$表示当前点的前$i$个儿子花费为$k$可以获得的最大的力量值。

然后肯定要先更新$g[][]$再以$g[][]$来更新$f[][][]$。

列出$g[i][j]$的状态转移方程就是:

$g[cnt][k]=max \{ f[son][tol \times edge_v][j] + g[cnt-1][k-j] \}$

其中$tol$表示当前点总共要合成的装备。

然后根据$g[i][k]$来更新$f[i][j][k]$:

$f[i][j][k]= max \{ g[cnt_{max}][k]+(tol-j) \times Power_i \} $

然后就能愉快的转移了。

我看其他人的代码关于$tol$的枚举是递减的从而减少不必要的memset。不是很理解,希望神犇留言告诉我QAQ,不过直接memset也不会超时。

//BZOJ 1017
//by Cydiater
//2016.10.26
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <ctime>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <bitset>
using namespace std;
#define ll long long
#define up(i,j,n)		for(int i=j;i<=n;i++)
#define down(i,j,n)		for(int i=j;i>=n;i--)
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
const int MAXN=1e4+5;
const int oo=1000000001;
inline int read(){
	char ch=getchar();int x=0,f=1;
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int N,M,len=0,LINK[MAXN],f[55][105][2005],Power[MAXN],Cost[MAXN],LIM[MAXN],indu[MAXN],g[55][MAXN],ans=0;
bool tag[MAXN];
struct edge{
	int y,next,v;
}e[MAXN];
namespace solution{
	inline void insert(int x,int y,int v){e[++len].next=LINK[x];LINK[x]=len;e[len].y=y;e[len].v=v;}
	void init(){
		memset(indu,0,sizeof(indu));
		N=read();M=read();
		up(i,1,N)LIM[i]=oo;
		up(i,1,N){
			Power[i]=read();char ch;scanf("%c",&ch);
			tag[i]=(ch=='A')?1:0;
			if(tag[i]){
				int tmp=read();
				while(tmp--){
					int y=read(),v=read();
					insert(i,y,v);indu[y]++;
				}
			}else{
				Cost[i]=read();LIM[i]=read();
			}
		}
	}
	void TreeDP(int node){
		if(!tag[node]){
			cmin(LIM[node],M/Cost[node]);
			up(i,0,LIM[node])up(j,0,i)
				f[node][j][i*Cost[node]]=Power[node]*(i-j);
		}else{
			LIM[node]=oo;
			for(int i=LINK[node];i;i=e[i].next){
				TreeDP(e[i].y);cmin(LIM[node],LIM[e[i].y]/e[i].v);
				Cost[node]+=e[i].v*Cost[e[i].y];
			}
			cmin(LIM[node],M/Cost[node]);
			up(tol,0,LIM[node]){
				int cnt=0;
				memset(g,-10,sizeof(g));g[0][0]=0;
				for(int i=LINK[node];i;i=e[i].next){
					cnt++;
					up(j,0,M)up(k,0,j)
						cmax(g[cnt][j],g[cnt-1][j-k]+f[e[i].y][e[i].v*tol][k]);
				}
				up(j,0,tol)up(k,0,M)cmax(f[node][j][k],g[cnt][k]+(tol-j)*Power[node]);
			}
		}
	}
	void output(int node){
		up(j,0,LIM[node])up(k,0,M)cmax(ans,f[node][j][k]);
	}
}
int main(){
	freopen("input.in","r",stdin);
	using namespace solution;
	init();
	memset(f,-10,sizeof(f));
	up(i,1,N)if(indu[i]==0){
		TreeDP(i);
		output(i);
	}
	cout<<ans<<endl;
	return 0;
}

BZOJ1017: [JSOI2008]魔兽地图DotR的更多相关文章

  1. [BZOJ1017][JSOI2008]魔兽地图DotR 树形dp

    1017: [JSOI2008]魔兽地图DotR Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 2597  Solved: 1010[Submit][ ...

  2. [bzoj1017][JSOI2008]魔兽地图 DotR (Tree DP)【有待优化】

    Description DotR (Defense of the Robots) Allstars是一个风靡全球的魔兽地图,他的规则简单与同样流行的地图DotA (Defense of the Anc ...

  3. BZOJ1017: [JSOI2008]魔兽地图DotR【树形DP】【玄学】

    Description DotR (Defense of the Robots) Allstars是一个风靡全球的魔兽地图,他的规则简单与同样流行的地图DotA (Defense of the Anc ...

  4. BZOJ1017 [JSOI2008]魔兽地图DotR 【树形dp + 背包dp】

    题目链接 BZOJ1017 题解 orz hzwer 树形dp神题 设\(f[i][j][k]\)表示\(i\)号物品恰好花费\(k\)金币,并将\(j\)个物品贡献给父亲的合成时的最大收益 计算\( ...

  5. bzoj1017 [JSOI2008]魔兽地图DotR——DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1017 好难想的状态啊!f[i][j][k]表示i号物品有j个向上贡献,一共花了k钱的最大力量 ...

  6. 【bzoj1017】[JSOI2008]魔兽地图DotR

    1017: [JSOI2008]魔兽地图DotR Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 1658  Solved: 755[Submit][S ...

  7. 【BZOJ-1017】魔兽地图DotR 树形DP + 背包

    1017: [JSOI2008]魔兽地图DotR Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 1566  Solved: 705[Submit][S ...

  8. BZOJ [JSOI2008]魔兽地图DotR

    1017: [JSOI2008]魔兽地图DotR Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 1243  Solved: 532[Submit][S ...

  9. 1017: [JSOI2008]魔兽地图DotR - BZOJ

    Description DotR (Defense of the Robots) Allstars是一个风靡全球的魔兽地图,他的规则简单与同样流行的地图DotA (Defense of the Anc ...

随机推荐

  1. backup, file manipulation operations (such as ALTER DATABASE ADD FILE) and encryption changes on a database must be serialized.

    昨天在检查YourSQLDba备份时,发现有台数据库做备份时出现了下面错误信息,如下所示: <Exec>   <ctx>yMaint.ShrinkLog</ctx> ...

  2. jquery本地上传预览扩展(隐藏上传控件单击图片上传支持ie!!)

    我用到的原材料地址:http://www.cnblogs.com/leejersey/p/3660202.html 修改后: /// <reference path="../../Js ...

  3. 浅谈iptables防SYN Flood攻击和CC攻击

    ------------------------本文为自己实践所总结,概念性的东西不全,这里粗劣提下而已,网上很多,本文主要说下目前较流行的syn洪水攻击和cc攻击------------------ ...

  4. Linux 服务器模型小结

    当我们用socket进行编程的时候,细节上都是选择一个AF_LOCAL,AF_INET再根据相应的类型填充地址,其实根据通信需求,有几种简单的服务模型可供选用,掌握了这些框架再结合socket高度的抽 ...

  5. Python列表list的用法

    #!usr/bin/env python# -*-coding:utf-8-*-#以下方法全在python2.7.x版本运行,请3.x以上的小伙伴们在print(放入括号内执行)#list列表的常用方 ...

  6. lmap

    1.lamp组件安装 sudo apt-get install apache2 sudo apt-get install php5 sudo apt-get install mysql-server ...

  7. 固态硬盘与机械硬盘 SQL Server 单表插入性能对比测试

    测试环境

  8. Java迷宫游戏

    缘起: 去年(大三上学期)比较喜欢写小游戏,于是想试着写个迷宫试一下. 程序效果: 按下空格显示路径: 思考过程: 迷宫由一个一个格子组成,要求从入口到出口只有一条路径. 想了一下各种数据结构,似乎树 ...

  9. Django博客功能实现—文章评论功能

    功能:在A网页提交一个评论Forms_B,提交之后自动刷新页面,能够显示刚刚的画面思路:利用一个已经创建的表单,通过视图让其在网页中表现出来,填写玩信息之后提交,会提交到一个新的视图里面去做接受,接受 ...

  10. Map接口,Map.Entry,hashMap类,TreeMap类,WeakHashMap。

    Collection接口之前接触过,每次保存的对象是一个对象,但是在map中保存的是一对对象,是以key->value形式保存的. 定义: public interface Map<K,V ...