P1642 规划
题目链接
题意分析
一看就知道是一道\(01\)分数规划的题
我们二分值之后 跑树形背包就可以了
CODE:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<queue>
#include<map>
#include<stack>
#include<list>
#include<set>
#include<deque>
#include<vector>
#include<ctime>
#define ll long long
#define inf 1e9
#define N 508
#define IL inline
#define M 1008611
#define D double
#define eps 1e-5
#define R register
using namespace std;
template<typename T>IL void read(T &_)
{
T __=0,___=1;char ____=getchar();
while(!isdigit(____)) {if(____=='-') ___=0;____=getchar();}
while(isdigit(____)) {__=(__<<1)+(__<<3)+____-'0';____=getchar();}
_=___ ? __:-__;
}
/*-------------OI使我快乐-------------*/
int n,m,tot;
struct Node
{
int xx,yy;
}e[N];
D dp[N][N],num[N];
D le,ri=inf,ans;
int siz[N],to[N],nex[N],head[N];
IL void add(int x,int y)
{to[++tot]=y;nex[tot]=head[x];head[x]=tot;}
IL void dfs(int now,int fat)
{
dp[now][0]=0;siz[now]=1;
for(R int i=head[now];i;i=nex[i])
{
int v=to[i];
if(v==fat) continue;
dfs(v,now);
siz[now]+=siz[v];
for(R int j=min(m,siz[now]);j>=0;--j)
for(R int k=0;k<=min(j,siz[v]);++k)
dp[now][j]=max(dp[now][j],dp[now][j-k]+dp[v][k]);
}
for(R int i=siz[now];i;--i) dp[now][i]=dp[now][i-1]+num[now];
}
IL bool check(D now)
{
for(R int i=1;i<=n;++i)
for(R int j=0;j<=m;++j) dp[i][j]=-inf;
for(R int i=1;i<=n;++i) num[i]=(D)e[i].xx-((D)now*e[i].yy);
dfs(1,0);
for(R int i=1;i<=n;++i)
if(dp[i][m]>-eps) return 1;
return 0;
}
int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
read(n);read(m);m=n-m;
for(R int i=1;i<=n;++i) read(e[i].xx);
for(R int i=1;i<=n;++i) read(e[i].yy);
for(R int i=1,x,y;i<n;++i)
{
read(x);read(y);
add(x,y);add(y,x);
}
while((ri-le)>eps)
{
D mid=(le+ri)/2.0;
if(check(mid)) ans=le=mid;
else ri=mid;
}
printf("%.1f\n",ans);
// fclose(stdin);
// fclose(stdout);
return 0;
}
HEOI 2019 RP++
P1642 规划的更多相关文章
- [洛谷P1642]规划
题目大意:有一棵$n(n\leqslant100)$个点的树,每个点有两个权值$a,b$,要求选择一个$m$个点的连通块$S$,最大化$\dfrac{\sum\limits_{i\in S}a_i}{ ...
- P1642 规划 01分数规划+树形DP
$ \color{#0066ff}{ 题目描述 }$ 某地方有N个工厂,有N-1条路连接它们,且它们两两都可达.每个工厂都有一个产量值和一个污染值.现在工厂要进行规划,拆除其中的M个工厂,使得剩下的工 ...
- luogu P1642 规划
嘟嘟嘟 看到最后让求一个比值,应该得往01规划上去想.令x = ∑v[i] / ∑c[i],则x * ∑c[i] = ∑v[i], ∑(v[i] - x * c[i]) = 0. 于是可以二分x(注意 ...
- P1642 规划 [01分数规划]
裸题,考虑size完了跑一个树上背包,这题没了. // by Isaunoya #include <bits/stdc++.h> using namespace std; #define ...
- shell脚本规划化模板
shell脚本规划化模板 Linux运维过程中,shell脚本是不可缺少的工具,但是每个运维人员编程的习惯都不一样,很多时候就是实现某个功能,写出来的脚本都是烂七八糟的.脚本必须规范化,应该从以后几个 ...
- IT基础架构规划方案一(网络系统规划)
背景 某集团经过多年的经营,公司业务和规模在不断发展,公司管理层和IT部门也认识到通过信息化手段可以更好地支撑公司业务运营.提高企业生产和管理效率.同时随着新建办公 ...
- 攻城记:Thinkphp框架的项目规划总结和踩坑经验
一.项目模块规划 1.项目分为PC端.移动端.和PC管理端,分为对应目录为 /Application/Home,/Application/Mobile,/Application/Admin: 对应入口 ...
- 【BZOJ-3627】路径规划 分层图 + Dijkstra + spfa
3627: [JLOI2014]路径规划 Time Limit: 30 Sec Memory Limit: 128 MBSubmit: 186 Solved: 70[Submit][Status] ...
- Google地图路线规划
Google地图路线规划: 需求:给定的两点之间Google地图路径规划和详情. 代码实现: //map定义省略 var directionsDisplay = new google.maps.Dir ...
随机推荐
- RemoteExt 远程验证
public class RemoteExtAttribute : RemoteAttribute { private string _resourceKey; public RemoteExtAtt ...
- Java程序设计9——泛型
泛型是对集合的补充,JDK1.5增加泛型支持很大程度上都是为了让集合能记住其元素的数据类型.在没有泛型之前,一旦把一个对象丢进Java集合中,集合就会忘记对象的类型,把所有的对象都当成Object类型 ...
- 475. Heaters
static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...
- Chrome Command Line API 参考
- UVaLive 3126 Taxi Cab Scheme (最小路径覆盖)
题意:有 n 个客人,要从 si 到 ti,每个人有一个出发时间,现在让你安排最少和出租车去接,在接客人时至少要提前一分钟到达客人的出发地点. 析:把每个客人看成一个结点,然后如果用同一个出租车接的话 ...
- CoderForces 689A Mike and Cellphone (水题)
题意:给定一个手机键盘数字九宫格,然后让你判断某种操作是不是唯一的,也就是说是不是可以通过平移也能实现. 析:我的想法是那就平移一下,看看能实现,就四种平移,上,下,左,右,上是-3,要注意0变成8, ...
- Git config 配置文件
一.Git已经在你的系统中了,你会做一些事情来客户化你的Git环境.你只需要做这些设置一次:即使你升级了,他们也会绑定到你的环境中.你也可以在任何时刻通过运行命令来重新更改这些设置. Git有一个工具 ...
- koa学习笔记
卸载node http://www.it165.net/os/html/201504/12427.html 安装 sudo npm install -g n sudo n stable 装个稳定版试试 ...
- 8.使用Exists监控ZNode的三大Change事件
一. zookeeper是一个分布式的协调程序(所有程序都是通过订阅它来相互感知) 1. tcp(长链接) + watcher server ->client client ->ser ...
- sitecore 缓存管理器
namespace XXX.Shared.Infrastructure.Caching { using System; using System.Collections.Generic; using ...