bzoj3875 【Ahoi2014】骑士游戏 spfa处理后效性动规
骑士游戏
Input
Output
输出一行一个整数,表示最少需要的体力值。
Sample Input
4
4 27 3 2 3 2
3 5 1 2
1 13 2 4 2
5 6 1 2
Sample Output
26
Hint
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#define N 200007
#define ll long long
using namespace std; vector<int>bc[N];//表示这个怪兽可以变成哪几个怪兽。
vector<int>zh[N];//表示该怪兽可以由哪几个怪兽要变成。 int n,r[N];
ll f[N],s[N],k[N];
bool ins[N]; int main()
{
scanf("%d",&n);
int x;
for (int i=;i<=n;i++)
{
scanf("%lld%lld%d",&s[i],&k[i],&r[i]);
for (int j=;j<=r[i];j++)
{
scanf("%d",&x);
bc[i].push_back(x);
zh[x].push_back(i);
}
}
for(int i=;i<=n;i++)
f[i]=k[i];
queue<int>q;
for (int i=;i<=n;i++)
q.push(i),ins[i]=;
while(!q.empty())
{
int u=q.front();q.pop();
ins[u]=;
ll sp=s[u];
for (int i=;i<bc[u].size();i++)
sp+=f[bc[u][i]];
if (sp>=f[u]) continue;
f[u]=sp;
for (int i=;i<zh[u].size();i++)
if (!ins[zh[u][i]])
{
q.push(zh[u][i]);
ins[zh[u][i]]=;
}
}
printf("%lld\n",f[]);
}
bzoj3875 【Ahoi2014】骑士游戏 spfa处理后效性动规的更多相关文章
- [bzoj3875] [Ahoi2014]骑士游戏
3875: [Ahoi2014]骑士游戏 Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 844 Solved: 440[Submit][Status ...
- BZOJ 3875: [Ahoi2014]骑士游戏 spfa dp
3875: [Ahoi2014]骑士游戏 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=3875 Description [故事背景] 长 ...
- [BZOJ3875][AHOI2014]骑士游戏(松弛操作)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3875 分析: 类似于spfa求最短路,设d[i]表示完全消灭i号怪物的最小花费,我们对 ...
- BZOJ 3875: [Ahoi2014]骑士游戏 dp+spfa
题目链接: 题目 3875: [Ahoi2014]骑士游戏 Time Limit: 30 Sec Memory Limit: 256 MB 问题描述 [故事背景] 长期的宅男生活中,JYY又挖掘出了一 ...
- BZOJ 3875: [Ahoi2014]骑士游戏
d[i]表示消灭i所需的最小体力值, d[i] = min(S[i], K[i]+Σd[x]), Σd[x]表示普通攻击而产生的其他怪兽. 因为不是DAG, 所以用个队列类似SPFA来更新答案. -- ...
- 【BZOJ3875】【AHOI2014】骑士游戏 [Spfa][DP]
骑士游戏 Time Limit: 30 Sec Memory Limit: 256 MB[Submit][Status][Discuss] Description 在这个游戏中,JYY一共有两种攻击 ...
- 【BZOJ3875】[Ahoi2014&Jsoi2014]骑士游戏 SPFA优化DP
[BZOJ3875][Ahoi2014&Jsoi2014]骑士游戏 Description [故事背景] 长期的宅男生活中,JYY又挖掘出了一款RPG游戏.在这个游戏中JYY会扮演一个英勇的 ...
- LUOGU P4042 [AHOI2014/JSOI2014]骑士游戏 (spfa+dp)
传送门 解题思路 首先设\(f[x]\)表示消灭\(x\)的最小花费,那么转移方程就是 \(f[x]=min(f[x],\sum f[son[x]] +s[x])\),如果这个转移是一个有向无环图,那 ...
- bzoj 3875 骑士游戏 - spfa - 动态规划
Description [故事背景] 长期的宅男生活中,JYY又挖掘出了一款RPG游戏.在这个游戏中JYY会 扮演一个英勇的骑士,用他手中的长剑去杀死入侵村庄的怪兽. [问题描述] 在这个游戏中,J ...
随机推荐
- 使用ant build build.xml报“includeantruntime was not set”警告及"Class not found: javac1.8"问题
问题1:ant编译build.xml报“includeantruntime was not set”警告. 警告详情: warning: 'includeantruntime' was not set ...
- Hello Shell
shell是Linux平台的瑞士军刀,能够自动化完成很多工作.要了解UNIX 系统中可用的 Shell,可以使用 cat /etc/shells 命令.使用 chsh 命令 更改为所列出的任何 She ...
- JAVA自带的加密算法-MD5\SHA1\BASE64
需要导入jar包: commons-codec.jar MD5 String str = "abc"; DigestUtils.md5Hex(str); SHA1 String s ...
- Kali 2017.3开启VNC远程桌面登录
通过启用屏幕共享来开启远程桌面登录,开启后需要关闭encryption,否则会出现无法连接的情况.关闭encryption可以使用系统配置工具dconf来完成.所以先安装dconf-editor. 更 ...
- libs/tools.js stringToDate dateToString 日期字符串转换函数
libs/tools.js stringToDate dateToString 日期字符串转换函数 import { stringToDate } from '@/libs/tools.js' e ...
- Mac 创建软链接
ln -s /Volumes/dzqExt/source/wukongqipai/wukongqipai/ccclient/Classes/ ./frameworks/runtime-src/ ...
- 数组、list排序
//数字排序 int[] intArray = new int[] {4, 1, 3, -23}; Arrays.sort(intArray); 输出: [-23, 1, 3, 4] //字符串排序, ...
- django模板系统的基本原则
写模板,创建template对象,创建 context ,调用render()方法
- Promise 理解与使用
个人觉得这篇博客写的非常详细且易懂,推荐给小伙伴们~ https://www.cnblogs.com/lvdabao/p/es6-promise-1.html#!comments
- attr和prop的区别
由于prop(property的缩写)和attr(attribute的缩写)翻译成汉语,均有“特性.属性”等意思的原因,导致大家容易混淆分不清. (1)在处理自定义时属性时,用attr(),若用pro ...