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> ...
随机推荐
- 预见2019吴晓波年终秀演讲PPT整理
在2018年倒数的第二天12月30日晚上7点在广东珠海横琴拉开帷幕,吴晓波以一场“预见2019”的年终盛典,和大家一起回望即将告别的跌宕一年,细数过去的焦虑和改变,瞭望未来的激越和走向.下面我们一起来 ...
- KinectFusion测试
谁告诉我说KinectFusion不能直接在Kinect2上直接用.今天心血来潮看了一下Kinect for Windows SDK中的头文件,发现完全可以用啊. 于是用SDK自带的Demo测试了一下 ...
- 算法笔记-PHP实现队列的操作
[队列]先进者先出,这就是典型的“队列”. 最基本的两个操作:入队enqueue(),放一个数据到队列尾部:出队dequeue(),从队列头部取一个元素.队列可以用数组或者链表实现,用 ...
- mybatis {arg0} 与 {0}
解决方案: MyBatis的XML的配置文件中声明设置属性的useActualParamName参数值为假 <setting name="useActualParamName" ...
- 23个适合logo设计的常用英文字体
在很多国外的品牌中我们都会发现他们的英文字体在logo的运用中,不仅会提升logo的品质还会让logo看起来更加美观.今天我们就来看看都有哪些常常出现在logo设计中的英文字体吧. 字体,与文字本 ...
- ODS与DW之间的关系
1.什么是数据仓库? 数据仓库是面向主题的.集成的.相对稳定的.反应历史变化的数据集合,主要用于决策支持和信息的全局共享. 时效:T+1 2.什么是ODS? ODS全称为Operational Dat ...
- 配置opensips经验总结
主要参考https://www.cnblogs.com/Forever-Kenlen-Ja/p/7741776.html (ubuntu),还有https://blog.csdn.net/sunyun ...
- Mac为python2.7.10安装pip
首先下载get-pip.py https://bootstrap.pypa.io/get-pip.py alias python="/usr/bin/python2.7" pyth ...
- openCV学习——一、图像读取、显示、输出
openCV学习——一.图像读取.显示.输出 一.Mat imread(const string& filename,int flags=1),用于读取图片 1.参数介绍 filename ...
- redis基本命令
1指定配置文件启动 ./redis-server /opt/server/redis/conf/redis.conf vim redis.conf #配置文件requirepass #后面跟密码 ...