POJ 1018 Communication System (动态规划)
By overall bandwidth (B) we mean the minimum of the bandwidths of the chosen devices in the communication system and the total price (P) is the sum of the prices of all chosen devices. Our goal is to choose a manufacturer for each device to maximize B/P.
Input
Output
Sample Input
- 1 3
- 3 100 25 150 35 80 25
- 2 120 80 155 40
- 2 100 100 120 110
Sample Output
- 0.649
- 题解:我们定义状态dp 【i】【j】 表示选择了前 i 个宽带其容量为 j 的最小费用
- 很容易得到转移方程 :dp【i】【j】=min(dp【i】【j】,dp【i-1】【k】+p);注意选择 j 的时候的大小情况
- #include <iostream>
- #include <algorithm>
- #include <cstring>
- #include <cstdio>
- #include <vector>
- #include <cstdlib>
- #include <iomanip>
- #include <cmath>
- #include <ctime>
- #include <map>
- #include <set>
- using namespace std;
- #define lowbit(x) (x&(-x))
- #define max(x,y) (x>y?x:y)
- #define min(x,y) (x<y?x:y)
- #define MAX 100000000000000000
- #define MOD 1000000007
- #define pi acos(-1.0)
- #define ei exp(1)
- #define PI 3.141592653589793238462
- #define INF 0x3f3f3f3f3f
- #define mem(a) (memset(a,0,sizeof(a)))
- typedef long long ll;
- ll gcd(ll a,ll b){
- return b?gcd(b,a%b):a;
- }
- bool cmp(int x,int y)
- {
- return x>y;
- }
- const int N=;
- const int mod=1e9+;
- const int inf = 0x3f3f3f3f;
- int dp[][];
- int main()
- {
- int t;
- scanf("%d",&t);
- while(T--){
- int n;
- scanf("%d",&n);
- for(int i=;i<=n;i++){
- for(int j=;j<;j++)
- dp[i][j]=inf;
- }
- for(int i=; i<=n; i++) {
- int num;
- scanf("%d",&num);
- for(int j=; j<=num;j++){
- int p,b;
- scanf("%d%d",&b,&p);
- if(i==){
- dp[][b]=min(dp[][b],p);
- }
- else{
- for(int k=;k<;k++){
- if(dp[i-][k]!=inf){
- if(k<=b)
- dp[i][k]=min(dp[i][k],dp[i-][k]+p);
- else
- dp[i][b]=min(dp[i][b],dp[i-][k]+p);
- }
- }
- }
- }
- }
- double ans=;
- for(int i=;i<;i++){
- if(dp[n][i]!=inf){
- double k=(double)i/dp[n][i];
- if(k>ans)
- ans=k;
- }
- }
- printf("%.3lf\n",ans);
- }
- return ;
- }
POJ 1018 Communication System (动态规划)的更多相关文章
- POJ 1018 Communication System(树形DP)
Description We have received an order from Pizoor Communications Inc. for a special communication sy ...
- poj 1018 Communication System
点击打开链接 Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21007 Acc ...
- poj 1018 Communication System 枚举 VS 贪心
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21631 Accepted: ...
- POJ 1018 Communication System(贪心)
Description We have received an order from Pizoor Communications Inc. for a special communication sy ...
- poj 1018 Communication System (枚举)
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22380 Accepted: ...
- POJ 1018 Communication System(DP)
http://poj.org/problem?id=1018 题意: 某公司要建立一套通信系统,该通信系统需要n种设备,而每种设备分别可以有m1.m2.m3.....mn个厂家提供生产,而每个厂家生产 ...
- POJ 1018 Communication System 贪心+枚举
看题传送门:http://poj.org/problem?id=1018 题目大意: 某公司要建立一套通信系统,该通信系统需要n种设备,而每种设备分别可以有m个厂家提供生产,而每个厂家生产的同种设备都 ...
- POJ 1018 Communication System 题解
本题一看似乎是递归回溯剪枝的方法.我一提交,结果超时. 然后又好像是使用DP,还可能我剪枝不够. 想了非常久,无奈忍不住偷看了下提示.发现方法真多.有贪心,DP,有高级剪枝的.还有三分法的.八仙过海各 ...
- poj 1018 Communication System_贪心
题意:给你n个厂,每个厂有m个产品,产品有B(带宽),P(价格),现在要你求最大的 B/P 明显是枚举,当P大于一定值,B/P为零,可以用这个剪枝 #include <iostream> ...
随机推荐
- python基础(9)-迭代器&生成器函数&生成器进阶&推导式
迭代器 可迭代协议和迭代器协议 可迭代协议 只要含有__iter__方法的对象都是可迭代的 迭代器协议 内部含有__next__和__iter__方法的就是迭代器 关系 1.可以被for循环的都是可迭 ...
- vue中使用lodash
1.安装:npm i --save lodash 2.引入:import _from 'lodash' 3.使用: <template> <div class="templ ...
- 八种排序算法--java实现(转)
(转:http://blog.csdn.net/without0815/article/details/7697916) 8种排序之间的关系: 1, 直接插入排序 (1)基本思想:在要排序的一组数中, ...
- nginx配置url重写
url重写是指通过配置conf文件,以让网站的url中达到某种状态时则定向/跳转到某个规则,比如常见的伪静态.301重定向.浏览器定向等 rewrite 语法 在配置文件的server块中写,如: s ...
- 关于时间的SQL语句
取当前时间: select current_timestamp; 输出:2016-06-16 16:12:52 select now(); 输出:2016-06-16 16:12:52 取当前时间的 ...
- go https ajax
这个很好用啊,估计大有用武之地 你会喜欢 //https-ajax.go package main import ( "fmt" "io" "net/ ...
- C# sapnco支持.net 4.5了,真是个意外的发现
意外篇: 需要用C#写一个RFC直连的类库,需要引用sapnco.dll sapnco_utils.dll两个文件 之前都是从网上下载的sapnco3.0,引用开发,在win10机器上使用没有问题 ...
- php函数addslashes()使用方法详解
实例 在每个双引号(")前添加反斜杠: <?php $str = addslashes('Shanghai is the "biggest" city in Chi ...
- Linux MySQL数据库文件同步及数据库备份
Mysql数据库链接 mysql -uroot -p -hdatacenter.jiaofukeyan.com -P33069 1.文件同步 rsync -avz --delete root@(需要同 ...
- selenium获取文本
# 标题list_title = driver.find_elements_by_xpath('//*[@id="share-content"]/div/div[1]/ul/li/ ...