bzoj 2306: [Ctsc2011]幸福路径
来源:互联网 发布:mac删除桌面文件 编辑:程序博客网 时间:2024/06/05 09:41
题意:在一个有向图中,一只蚂蚁在上面爬,每爬过一条边体力就*ρ,经过一个点获得点权*体力的收益,求最大收益。
题解:倍增floyd。因为蚂蚁可以无限走下去,直接求貌似不现实,但是体力下降得非常快,所以走足够多次就可以进入答案的误差允许范围内了。
f[i][j][l]表示从i点走到j点走2^l步的收益。
滚一下就可以了。
代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int n,m,s;double f[110][110],g[110][110],p,a[110];int main(){ memset(f,0xc2,sizeof(f));// printf("%lf",f[0][0][0]); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%lf",&a[i]); scanf("%d%lf",&s,&p); for(int i=1;i<=n;i++) f[i][i]=0; for(int i=0;i<m;i++) { int x,y; scanf("%d%d",&x,&y); f[x][y]=a[y]; } double hh=p; for(int l=0;l<=70;l++) { memset(g,0xc2,sizeof(g)); for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) g[i][j]=max(g[i][j],f[i][k]+f[k][j]*hh); hh*=hh; memcpy(f,g,sizeof(f)); } double ans=0; for(int i=1;i<=n;i++) ans=max(ans,f[s][i]); printf("%.1lf",ans*p+a[s]);}
阅读全文
1 0
- BZOJ 2306: [Ctsc2011]幸福路径
- [bzoj]2306: [Ctsc2011]幸福路径
- bzoj 2306: [Ctsc2011]幸福路径
- bzoj 2306: [Ctsc2011]幸福路径
- BZOJ 2306 Ctsc2011 幸福路径 倍增Floyd
- bzoj 2306: [Ctsc2011]幸福路径 倍增+floyed
- 2306: [Ctsc2011]幸福路径
- BZOJ 2306 [Ctsc2011] 幸福路径 [倍增+floyd做法]
- BZOJ 2306 [Ctsc2011] 幸福路径 [期望DP做法]
- BZOJ2306/Ctsc2011 幸福路径
- BZOJF2306 [Ctsc2011]幸福路径
- bzoj 2306 幸福路径 【floyd】【dp】
- 【bzoj2360】【cstc2011】【幸福路径】【倍增+floyd】
- 【重口味。。】CTSC2011杀菌计划
- 【BZOJ】【双倍的幸福】【双(三)倍的经验】
- BZOJ 2500 幸福的道路 树形DP+单调队列
- bzoj 2500: 幸福的道路 动态规划+单调栈
- bzoj 2500 幸福的道路 dfs 单调队列
- flume“Space for commit to queue couldn't be acquired”异常产生分析
- 笔试编程题之查找数组的位置
- win10 uwp 进度条 WaveProgressControl
- 矩阵快速幂优化菲波那切数列
- LeetCode(617) Merge Two Binary Trees
- bzoj 2306: [Ctsc2011]幸福路径
- bzoj 2044三维导弹拦截 二分图匹配
- xlistView_header的布局
- ORB_SLAM编译环境搭建过程当中遇到的问题
- 131. Palindrome Partitioning
- leetcode 128. Longest Consecutive Sequence
- Head First设计模式之迭代器模式
- No valid bower.json was found in any branch ...
- Python字符串格式化--format()方法