这个题目一开始不知道如何下手,感觉很像背包,里面有两个变量,一个带宽B,一个价格P,有n个设备,每个设备有k个可选的器材(只需选一个),每个器材都有自己的B和P,

n个设备选n个器材,最终,FB=所有器材里最小的B,FP=总的价格,要使得FB/FP最大

这种题目得先把一个变量给控制起来,或者说枚举其中一个变量之后,再通过dp的方法得到另一个变量的最优值,千万别想一步登天

像这个题目,我们如果先把每个设备对应的器材按价格升序排序,然后我枚举可能的FB,对于每个设备,我从前往后扫,一旦扫到了B>=FB(合法数据),就停止,取该值,最后扫完整个n个设备,得到的值必定是我枚举 的FB对应的最大FB/FP,这个显而易见嘛。。因为数据量不大,所以可以用。当然我算了下峰值的复杂度可以达到10的8次方,但是其实达不到,其中很难每个循环都运行完。

其实这样看来倒不像DP了,其实是暴力枚举了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
struct node
{
int b,v;
bool operator < (const node&rhs) const{
return v<rhs.v;
}
};
vector<node>G[110];
int B[10010];
int n,cnt;
int main()
{
int t;
scanf("%d",&t);
while (t--)
{
cnt=0;
scanf("%d",&n);
for (int i=0;i<=n;i++) G[i].clear();
for (int i=1;i<=n;i++){
int k,a,b;
scanf("%d",&k);
while (k--){
scanf("%d%d",&a,&b);
B[cnt++]=a;
G[i].push_back((node){a,b});
}
sort(G[i].begin(),G[i].end());
}
sort(B,B+cnt);
int m=0;
for (int i=1;i<cnt;i++){
if (B[i]!=B[i-1]) B[++m]=B[i];
}
double ans=0.0;
for (int i=0;i<=m;i++){
bool flag=1;
double sum=0;
for (int j=1;j<=n && flag;j++){
int r=G[j].size();
for (int k=0;k<r;k++){
if (G[j][k].b>=B[i]){
sum+=(double)G[j][k].v;
break;
}
if (k==r-1 && G[j][k].b<B[i])flag=0;
}
}
if (!flag) continue;
ans=max(ans,(double)B[i]*1.0/sum);
}
printf("%.3f\n",ans);
}
return 0;
}

  

ZOJ 1409 communication system 双变量型的DP的更多相关文章

  1. zoj 1409 Communication System

    /*如果要一个物体的多种属性,最好用结构体,不要用二维数组或者多维数组.用多维数组进行关键字排序很不稳定 */ /*给每个设备的所有价格排序,每个设备选取恰好比已知带宽大的价格(这个时候的比例最大) ...

  2. 《BI那点儿事》双变量的相关分析——相关系数

    例如,“三国人物是否智力越高,政治就越高”,或是“是否武力越高,统率也越高:准备数据分析环境: SELECT * FROM FactSanguo11 WHERE 姓名 IN ( N'荀彧', N'荀攸 ...

  3. Communication System(dp)

    Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25006 Accepted: 8925 ...

  4. poj 1018 Communication System

    点击打开链接 Communication System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21007   Acc ...

  5. poj 1018 Communication System 枚举 VS 贪心

    Communication System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21631   Accepted:  ...

  6. 双T型陷波滤波器

    有时,我们需要设计个滤波器滤除特定一个频率的噪音.这时就需要陷波滤波器了. 陷波器是带阻滤波器的一种,带阻滤波器的滤除频率有一定宽度,而陷波就是对某一个频率噪音的滤除. 双T型陷波滤波器应该是最常见的 ...

  7. POJ 1018 Communication System(贪心)

    Description We have received an order from Pizoor Communications Inc. for a special communication sy ...

  8. F - Communication System

    We have received an order from Pizoor Communications Inc. for a special communication system. The sy ...

  9. POJ 1018 Communication System (动态规划)

    We have received an order from Pizoor Communications Inc. for a special communication system. The sy ...

随机推荐

  1. Ubuntu下安装GTK的三种方法

    我利用此方法成功在UBUNTU 10.04下安装GTK 2.20.1. 一.安装 1.安装gcc/g++/gdb/make 等基本编程工具 $sudo apt-get install build-es ...

  2. windows服务使用和控制启停

    https://www.cnblogs.com/mq0036/p/7875864.html

  3. python 中的 *args 和 **kwargs

    在阅读Python代码时,经常会看到如下函数的定义: def fun(*args, **kwargs): 很多同学可能会对此感到困惑,这个 * args和 **kwargs是什么东西.为啥会在源码中应 ...

  4. java中常用的数据结构--Collection接口及其子类

    java中有几种常用的数据结构,主要分为Collection和map两个主要接口(接口只提供方法,并不提供实现),而程序中最终使用的数据结构是继承自这些接口的数据结构类. 一.集合和数组的区别 二.C ...

  5. Spark教程——(5)PySpark入门

    启动PySpark: [root@node1 ~]# pyspark Python 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 ...

  6. vscode git 提交数据到分支

        1.vscode菜单--终端--新建终端   git config --global user.name "your name"   git config --global ...

  7. input 数值框处理

    <input type="text"> input  若设置type=“number” ,再想对其调用处理的函数是不起作用的,为此,首先将其设为文本类型 当前要求是数字 ...

  8. ibd2sdi — InnoDB表空间SDI提取实用程序

    参考mysql8.0官方文档 https://dev.mysql.com/doc/refman/8.0/en/ibd2sdi.html ibd2sdi是一个实用程序,用于从表空间文件中提取 序列化的字 ...

  9. Wincc V7.3SE安装截图

    打开某个工程出错,能力所限,找不到问题,没能解决

  10. 通过css 居中div的几种常用方法

    1.text-align:center方式 .center{ text-align:center; } center_text{ display:inline-block; width:500px } ...