[CodeVS4438]YJQ Runs Upstairs
[CodeVS4438]YJQ Runs Upstairs
题目大意:
一个\(n(n\le50)\)个点\(m(m\le300)\)条边的DAG,保证从\(1\)到\(n\)的所有路径经过边数均小于等于\(20\)。每条边有一个边权\(w_i(w_i\le50)\),求从\(1\)到\(n\)经过边权方差最小值。
思路:
\]
\(f[i][j][k]\)表示\(1\sim i\)的路径经过\(j\)条边,\(\sum w_i=k\)时,\(\sum w_i^2\)的最小值。根据拓扑序DP即可。
源代码:
#include<queue>
#include<cstdio>
#include<cctype>
#include<vector>
#include<cstring>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return x;
}
const int N=51,D=21,W=1001;
struct Edge {
int to,w;
};
std::vector<Edge> e[N];
inline void add_edge(const int &u,const int &v,const int &w) {
e[u].push_back((Edge){v,w});
}
int n,m,f[N][D][W],ind[N];
std::queue<int> q;
inline void upd(int &a,const int &b) {
a=std::min(a,b);
}
inline void kahn() {
f[1][0][0]=0;
for(register int i=1;i<=n;i++) {
if(!ind[i]) q.push(i);
}
while(!q.empty()) {
const int &x=q.front();
for(unsigned i=0;i<e[x].size();i++) {
const int &y=e[x][i].to,&w=e[x][i].w;
for(register int i=0;i+1<D;i++) {
for(register int j=0;j+w<W;j++) {
upd(f[y][i+1][j+w],f[x][i][j]+w*w);
}
}
if(!--ind[y]) q.push(y);
}
q.pop();
}
}
int main() {
memset(f,0x3f,sizeof f);
n=getint(),m=getint();
for(register int i=0;i<m;i++) {
const int u=getint(),v=getint();
add_edge(u,v,getint());
ind[v]++;
}
kahn();
double ans=1e9;
for(register int i=1;i<D;i++) {
for(register int j=0;j<W;j++) {
ans=std::min(ans,(f[n][i][j]-1.*j*j/i)/i);
}
}
printf("%.4f\n",ans);
return 0;
}
[CodeVS4438]YJQ Runs Upstairs的更多相关文章
- memory runs at single channel问题解决
memory runs at single channel 解决方案:开机后按DEL ,然后进入BIOS 选择第一项,回车! advanced下面的有个momori什么什么的,选择disable. m ...
- What To Do When MySQL Runs Out of Memory: Troubleshooting Guide
In this article, I will show you how to use the new version of MySQL (5.7+) and how to troubleshoot ...
- 时间同步ctss与ntp的关系【CTSSD Runs in Observer Mode Even Though No Time Sync Software is Running (Doc ID 1054006.1) 】
CTSSD Runs in Observer Mode Even Though No Time Sync Software is Running (Doc ID 1054006.1) In this ...
- 【CF896D】Nephren Runs a Cinema 卡特兰数+组合数+CRT
[CF896D]Nephren Runs a Cinema 题意:一个序列中有n格数,每个数可能是0,1,-1,如果一个序列的所有前缀和都>=0且总和$\in [L,R]$,那么我们称这个序列是 ...
- Jmeter-Maven-Plugin高级应用:Configuring the jvm that the jmeter process runs in
Configuring the jvm that the jmeter process runs in The JMeter Maven plugin will run the JMeter proc ...
- CodeForces - 896D :Nephren Runs a Cinema(卡特兰数&组合数学---比较综合的一道题)
Lakhesh loves to make movies, so Nephren helps her run a cinema. We may call it No. 68 Cinema. Howev ...
- 【CZY选讲·Yjq的棺材】
题目描述 Yjq想要将一个长为宽为的矩形棺材(棺材表面绝对光滑,所以棺材可以任意的滑动)拖过一个L型墓道. 如图所示,L型墓道两个走廊的宽度分别是和,呈90°,并且走廊的长度远大于. 现在Hja ...
- MCP|LQ|DIAlignR provides precise retention time alignment across distant runs in DIA and targeted proteomics
文献名: DIAlignR provides precise retention time alignment across distant runs in DIA and targeted prot ...
- PPID=1 runs as a background process, rather than being under the direct control of an interactive user
https://en.wikipedia.org/wiki/Daemon_(computing) [后台进程,非互动] d 结尾 syslogd 系统日志记录 sshd 响应ssh连接请求 In mu ...
随机推荐
- Python3学习笔记25-logging模块
logging模块,Python自带用来记录日志的模块. 因为工作需要用到关于日志的,最近一直都在看关于日志模块的东西,百度了很多文章,可惜都是看的让人一头雾水,最后运气不错,找到一篇很详细的文章.传 ...
- BZOJ 3498: PA2009 Cakes 一类经典的三元环计数问题
首先引入一个最常见的经典三元环问题. #include <bits/stdc++.h> using namespace std; const int maxn = 100005; vect ...
- Mac android studio 一直卡在Gradle:Build Running的解决办法
1.找到路径/Users/michael/.gradle/wrapper/dists/gradle-4.1-all/bzyivzo6n839fup2jbap0tjew,在此文件夹下有一个gradle版 ...
- spring事物回滚遇到的问题
在service层使用声明式事务添加@Transactional(rollbackFor = Exception.class)注解 多个方法进行数据库操作,执行失败则隐式的回滚事务,但是已经成功的发方 ...
- nodejs服务器读取图片返回给前端(浏览器)显示
1 前言 项目需要用nodejs服务器给前端传递图片,网上找了好多资料,多数都是怎么在前端上传图片的,然后通过看runoob.com菜鸟教程,发现其实是非常简单,用express框架就行了. 2 代码 ...
- JDK1.5引入的concurrent包
并发是伴随着多核处理器的诞生而产生的,为了充分利用硬件资源,诞生了多线程技术.但是多线程又存在资源竞争的问题,引发了同步和互斥,并带来线程安全的问题.于是,从jdk1.5开始,引入了concurren ...
- Python-HTML基础
1.HTML 1.HTML是什么 超文本标记语言,即学习这门语言就是在一堆标记 2.为何要用? 标记文本 3.如何用? HTML标签就是用来做记号的,虽然这些记号自带一些样式,但务必忽略掉记号的样式, ...
- Annoy 近邻算法
Annoy 随机选择两个点,以这两个节点为初始中心节点,执行聚类数为2的kmeans过程,最终产生收敛后两个聚类中心点 二叉树底层是叶子节点记录原始数据节点,其他中间节点记录的是分割超平面的信息 但是 ...
- composer 安装依赖缓慢,查看 composer 的详细执行日志
在 windows WSL 上安装 composer 依赖 composer install 发现执行异常缓慢,怀疑没有走国内的镜像,而是直接访问的 github. 需要能看到 composer 的执 ...
- 性能测试三十四:jvm内存结构(栈、堆、永久代)
Java内存管理机制 Java采用了自动管理内存的方式Java程序是运行在Jvm之中的Java的跨平台的基于Jvm的跨平台特性内存的分配和对象的创建是在Jvm中用户可以通过一系列参数来配置Jvm Jv ...