POJ 1018 Communication System
来源:互联网 发布:linux开机选择系统 编辑:程序博客网 时间:2024/06/06 19:02
题目点我
这道题有很多做法,贪心和搜索啥的都可以, 这里写动态规划的做法。
题目大意是说有一个通信系统,需要
如果定义状态
从这个例子可以观察到当前状态定义表达能力不够,无法体现
由于
边界条件
#include <stdio.h>#include <stdlib.h>#include <string.h>#define maxn 105#define maxm 105#define maxbw 10000#define inf 0x3f3f3f3fint dp[maxn][maxbw], m[maxn];int bw[maxn][maxm], p[maxn][maxm];int B[maxn * maxm], Bcnt;int min(int a, int b){ return a > b ? b : a;}long double max(long double a, long double b){ return a > b ? a : b;}long double solve(int n){ int i, j, k; for(i = 0; i < m[0]; i++){ dp[0][bw[0][i]] = min(p[0][i], dp[0][bw[0][i]]); } for(i = 1; i < n; i++){ for(j = 0; j < Bcnt; j++){ if(dp[i-1][B[j]] < inf){ for(k = 0; k < m[i]; k++){ if(bw[i][k] >= B[j]) dp[i][B[j]] = min(dp[i][B[j]], dp[i-1][B[j]] + p[i][k]); else dp[i][bw[i][k]] = min(dp[i][bw[i][k]], dp[i-1][B[j]] + p[i][k]); } } } } long double ans = 0; for(i = 0; i < Bcnt; i++){ if(dp[n-1][B[i]] < inf) ans = max(ans, long double(B[i]) / long double(dp[n-1][B[i]])); } return ans;}int main(){ int t, n; int i, j, k; scanf("%d", &t); while(t--){ memset(dp, 0x3f, sizeof(dp)); scanf("%d", &n); Bcnt = 0; for(i = 0; i < n; i++){ scanf("%d", &m[i]); for(j = 0; j < m[i]; j++){ scanf("%d %d", &bw[i][j], &p[i][j]); B[Bcnt++] = bw[i][j]; } } printf("%.3lf\n", solve(n)); } return 0;}
0 0
- poj 1018 Communication System
- POJ 1018 Communication System
- poj 1018 Communication System
- POJ 1018 Communication System
- POJ 1018 Communication System
- POJ 1018 Communication System
- poj 1018 Communication System
- POJ 1018 Communication System
- poj 1018 Communication System
- poj 1018 Communication System
- POJ 1018 Communication System
- poj 1018 Communication System
- poj 1018 Communication System
- poj-1018 Communication System
- POJ-1018 Communication System
- [POJ][1018]Communication System
- poj 1018Communication System
- poj 1018:Communication System
- 美图内网漫游(沦陷大量内部系统、内部服务器权限、企业架构、企业邮箱等敏感信息) - rsync,fastcgi
- UITableView 使用 selectRowAtIndexPath 不能默认选中cell的问题
- JAVA最多支持多少个线程
- Model绑定机制3:集合+字典
- 程序中三种不同的出错处理方式比较
- POJ 1018 Communication System
- C++构造函数
- [LeetCode]Course Schedule
- 一元二次方程求解
- Android开发实例透明效果设置方法
- kohana路由目录作为参数
- GRE写作必备句型
- 理解Spark的核心RDD
- 【整理】python 中 self, init, __ ,if __name__ == '__main__'