Codeforces183D T-shirt
这题好神啊……(然而我连每种物品贡献独立都没看出来……
首先$O(n^2 m)$的DP肯定都会写,然后可以发现每种物品一定是选得越多再选一个的收益就越低,因此可以用一个堆维护当前收益最高的物品,每次贪心取收益最高的那个并重新计算贡献……(当然不用堆也行,暴力扫就可以了……)
别问我为什么输出小数点后1000位,我不开心想调戏评测机玩……(然而好像到了一定位数之后就不会再输出了……所以我输出小数点后1亿位但实际上只输出了几百位的样子……
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn=,maxm=;
struct A{
int x;
double w;
A(int x,double w):x(x),w(w){}
bool operator<(const A &a)const{return w<a.w;}
};
priority_queue<A>heap;
double p[maxn][maxm],f[maxn][maxm],g[maxn],ans=0.0;
int n,m;
int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)for(int j=;j<=m;j++){
scanf("%lf",&p[i][j]);
p[i][j]/=1000.0;
}
for(int j=;j<=m;j++){
for(int i=;i<=n;i++)f[i][j]=p[i][j]+f[i-][j]*(1.0-p[i][j]);
heap.push(A(j,f[n][j]));
}
for(int i=;i<=n;i++){
A t=heap.top();
heap.pop();
ans+=t.w;
for(int i=;i<=n;i++)g[i]=f[i-][t.x]*p[i][t.x]+g[i-]*(-p[i][t.x]);
heap.push(A(t.x,g[n]));
for(int i=;i<=n;i++)f[i][t.x]=g[i];
}
printf("%.1000lf",ans);
return ;
}
Codeforces183D T-shirt的更多相关文章
- 新概念英语(1-11)Is this your shirt ?
Is this your shirt?Whose shirt is white? A:Whose shirt is that? Is this your shirt, Dave? Dave:No si ...
- Windows 10文件夹Shirt+鼠标右键出现“在此处打开命令窗口”
Windows 10文件夹Shirt+鼠标右键出现“在此处打开命令窗口” Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directo ...
- SELECT s.* FROM person p INNER JOIN shirt s ON s.owner = p.id WHERE p.name LIKE 'Lilliana%' AND s.color <> 'white';
SELECT s.* FROM person p INNER JOIN shirt sON s.owner = p.idWHERE p.name LIKE 'Lilliana%'AND s.color ...
- [Eclipse插件] Eclipse设置Tab键为空格(ctrl+shirt+f格式化生效)!
自定义format格式,用空格替换Tab键,ctrl+shit+f格式化后生效: 设置Eclipse中按Tab键为4个空格,这里标记下! Window-->Preferences-->Ja ...
- javascript arguments(转)
什么是arguments arguments 是是JavaScript里的一个内置对象,它很古怪,也经常被人所忽视,但实际上是很重要的.所有主要的js函数库都利用了arguments对象.所以agru ...
- Linux.NET实战手记—自己动手改泥鳅(下)
在上回合中,我们不痛不痒的把小泥鳅的数据库从只能供在Windows下运行的Access数据库改为支持跨平台的MYSQL数据库,毫无营养的修改,本回合中,我们将把我们修改后得来的项目往Linux中部署. ...
- MySQL基础
数据库操作 ---终端使用数据库 mysql -u root -p 之后回车键 输入密码 ---显示所有数据库: show databases; ---默认数据库: mysql - 用户权限相关数据 ...
- Swift3.0P1 语法指南——构造器
原档:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programmi ...
- Python之美--Decorator深入详解
转自:http://www.cnblogs.com/SeasonLee/archive/2010/04/24/1719444.html 一些往事 在正式进入Decorator话题之前,请允许我讲一个小 ...
随机推荐
- pop控制器
1.寻找指定的控制器MineViewControllerclass UIViewController *mineVC = nil; for (UIViewController * controller ...
- Angular material mat-icon 资源参考_Editor
ul,li>ol { margin-bottom: 0 } dt { font-weight: 700 } dd { margin: 0 1.5em 1.5em } img { height: ...
- head first
1, insert 单引号时,使用/转义 2, 不要用NULL, 查找时使用isNull 来判断. 3, 用and / or 连接两个not 时,要写两个NOT 4,delete from tab ...
- genkins的报错排查
[ERROR] /root/.jenkins/workspace/car/src/main/java/com/zhengxin/tool/code/Code.java:[20,64] diamond ...
- mongo嵌套查询
db.getCollection('TradeBookingRepresentation').find({uitid:'168282:20190214010009224', tradeVersion: ...
- 本地DataGrip连接阿里云MySQL
1.阿里云上开通MySQL端口 2.MySQL上的设置 1⃣️mysql -uroot -p2⃣️create user 'usrabc'@'%' identified by 'usrabc'; 3. ...
- bundle 与 package
bundle是Apple提供的软件安装的便捷方法. bundle为用户和开发者提供了一个简单地接口. bundle 和 package package:看起来像一个文件的目录 bundle ...
- ImportError: No module named 'tkinter'
环境说明: windows7.vscode1.33.1.python3.7.0. 解决方案: 通过安装程序单独卸载“tcl/tk and IDLE”------重新安装“tcl/tk and IDLE ...
- 前端+php实现概率抽奖
转前端之后,后台工程师大大跑路了只能兼任他的位置写点东西了 前端+后台抽奖代码网上一大堆,引用一位仁兄前面的代码(比较懒抱歉,后面数据处理,奖项判断是否抽完我将会标红,因为前面的代码网上太多了都能找到 ...
- js中的new操作符与Object.create()的作用与区别
js中的new操作符与Object.create()的作用与区别 https://blog.csdn.net/mht1829/article/details/76785231 2017年08月06日 ...