POJ 1018 Communication System(DP)
http://poj.org/problem?id=1018
题意:
某公司要建立一套通信系统,该通信系统需要n种设备,而每种设备分别可以有m1、m2、m3、...、mn个厂家提供生产,而每个厂家生产的同种设备都会存在两个方面的差别:带宽bandwidths 和 价格prices。
现在每种设备都各需要1个,考虑到性价比问题,要求所挑选出来的n件设备,要使得B/P最大。
其中B为这n件设备的带宽的最小值,P为这n件设备的总价。
思路:DP解决。
d[i][j]代表选择第i个设备时最小带宽j时的价格。
状态转移方程就是d[i][j]=min{d[i-1][k]+p,d[i][j]}。
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std; const int INF = 0x3f3f3f3f;
const int maxn = + ; int n,m; int dp[maxn][]; int main()
{
//freopen("D:\\txt.txt", "r", stdin);
int t, b, p;
cin >> t;
while (t--)
{
memset(dp, INF, sizeof(dp));
cin >> n;
for (int i = ; i < n; i++)
{
cin >> m;
for (int j = ; j < m; j++)
{
cin >> b >> p;
if (i == )
dp[i][b] = p;
else
{
for (int k = ; k < ; k++)
{
if (dp[i - ][k] != INF)
{
if (k <= b)
dp[i][k] = min(dp[i - ][k] + p, dp[i][k]);
else
dp[i][b] = min(dp[i - ][k] + p, dp[i][b]);
}
}
}
}
}
double ans = ;
for (int k = ; k < ; k++)
{
if (dp[n - ][k] != INF)
{
double c = (double)k / dp[n - ][k];
if (c>ans) ans = c;
}
}
cout << setiosflags(ios::fixed) << setprecision() << ans << endl;
}
return ;
}
POJ 1018 Communication System(DP)的更多相关文章
- POJ 1018 Communication System (动态规划)
We have received an order from Pizoor Communications Inc. for a special communication system. The sy ...
- POJ 1018 Communication System(贪心)
Description We have received an order from Pizoor Communications Inc. for a special communication sy ...
- POJ 1018 Communication System(树形DP)
Description We have received an order from Pizoor Communications Inc. for a special communication sy ...
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
- Communication System(动态规划)
个人心得:百度推荐的简单DP题,自己做了下发现真得水,看了题解发现他们的思维真得比我好太多太多, 这是一段漫长的锻炼路呀. 关于这道题,我最开始用DP的思路,找子状态,发现自己根本就不会找DP状态数组 ...
- POJ 3858 Hurry Plotter(DP)
Description A plotter is a vector graphics printing device that connects to a computer to print grap ...
- POJ - 2385 Apple Catching (dp)
题意:有两棵树,标号为1和2,在Tmin内,每分钟都会有一个苹果从其中一棵树上落下,问最多移动M次的情况下(该人可瞬间移动),最多能吃到多少苹果.假设该人一开始在标号为1的树下. 分析: 1.dp[x ...
- 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: ...
随机推荐
- 004-spring cloud gateway-网关请求处理过程
一.网关请求处理过程 客户端向Spring Cloud Gateway发出请求.如果网关处理程序映射确定请求与路由匹配,则将其发送到网关Web处理程序.此处理程序运行通过特定于请求的过滤器链发送请求. ...
- Y2K Accounting Bug(poj2586)
题意: 有一个公司由于某个病毒使公司赢亏数据丢失,但该公司每月的 赢亏是一个定数,要么一个月赢利s,要么一月亏d.现在ACM只知道该公司每五个月有一个赢亏报表,而且每次报表赢利情况都为亏.在一年中这样 ...
- Py中的多维数组ndarray学习【转载】
转自:http://blog.sciencenet.cn/home.php?mod=space&uid=3031432&do=blog&id=1064033 1. NumPy中 ...
- [LeetCode] 513. Find Bottom Left Tree Value_ Medium tag: BFS
Given a binary tree, find the leftmost value in the last row of the tree. Example 1: Input: 2 / \ 1 ...
- 机器学习理论基础学习3.1--- Linear classification 线性分类之感知机PLA(Percetron Learning Algorithm)
一.感知机(Perception) 1.1 原理: 感知机是二分类的线性模型,其输入是实例的特征向量,输出的是事例的类别,分别是+1和-1,属于判别模型. 假设训练数据集是线性可分的,感知机学习的目标 ...
- eigen 笔记1
c++ 的 eigen 类似于 python 的 numpy, 还有一个类似的库是 Armadillo, 当然还有 opencv. Armadillo 与 matlab 在函数名称上更接近, 但是 T ...
- Summary: 书架问题
Consider the problem of storing n books on shelves in a library. The order of the books is fixed by ...
- POJ 3461 Oulipo(KMP,模式串在主串中出现次数 可重叠)
题意:给你两个字符串p和s,求出p在s中出现的次数. 显然,我们要先把模式串放到前面,之后主串放后面,中间隔开,这样就可以根据前缀数组的性质来求了. 我先想直接把p接到s前面,之后求Next数组对st ...
- 剑指offer3
输入一个链表,从尾到头打印链表每个节点的值. 思路:首先借助一个栈,遍历链表中的每一个值,然后存储到栈中,利用栈的先进后出特点,然后添加到数组中返回. package demo3; import ja ...
- windows配置承载网络的一个批处理程序
@rem 这是windows中创建承载网络的相关命令title wifi热点@echo off set ssid=abcdeset key=123456789 :beginclsecho ------ ...