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> ...
随机推荐
- 帝国cms如何调用指定id的文章到首页?
小美女用帝国cms建了一个站,现在首页调出指定id为12的文章作为推荐,附带文章摘要,她想用代码的形式直接掉用,以后方便修改.那么,帝国cms如何调用指定id的文章呢?指定信息id,不是调用指定栏目i ...
- 如何调用finecms指定栏目的描述关键词
有时我们在用finecms建站时需要调用指定栏目的描述和关键词,实现个性化需求,比如id为23的栏目很重要,要让它在首页展示出来,这时我们要如何调用呢?{dr_cat_value(23, 'name' ...
- PXE安装操作系统
TFTP服务 用PXE安装操作系统依赖于DHCP服务和TFTP服务 网卡一般都内置的TFTP客户端的程序 systemctl enable tftp systemctl enable dhc ...
- 【leetcode】部分思路整理
题目: 求一个树的最小深度. 思路: 思路一:递归 若为空树返回0: 若左子树为空,则返回右子树的最小深度+1:(加1是因为要加上根这一层,下同) 若右子树为空,则返回左子树的 ...
- 【分类器】感知机+线性回归+逻辑斯蒂回归+softmax回归
一.感知机 详细参考:https://blog.csdn.net/wodeai1235/article/details/54755735 1.模型和图像: 2.数学定义推导和优化: 3.流程 ...
- vux icon
官网:https://doc.vux.li/zh-CN/components/icon.html <icon type="success"></icon>& ...
- crontab 详解
1.crontab文件格式 {minute} {hour} {day-of-month} {month} {day-of-week} {full-path-to-shell-script} ● mi ...
- shell for 循环数组
name=(aa bb) ;i<${#name[*]};i++)) do name=${name[i]} echo "$name" done
- JS控制文本框只能输入数字 \保留小数点后两位
<input type="text" placeholder="保留到小数点后两位" maxlength="200" onkeyup= ...
- RCNN系列算法的发展
一. RCNN系列的发展 1.1 R-CNN 根据以往进行目标检测的方法,在深度学习应用于目标检测时,同样首先尝试使用滑动窗口的想法,先对图片进行选取2000个候选区域,分别对这些区域进行提取特征以 ...