Codeforces Round #160 (Div. 2) D. Maxim and Restaurant(DP)
想了挺久,枚举每一件物品,当做关键物品,假设再加这一件物品,就>=c了,把剩下的物品背一下包,dp[i][j]表示i个物品可以组成重量j的个数。
这样就可以知道前面放i件,后边肯定放n-i-1件,乱搞搞,算double,边乘边算保证不要越界。最后注意,LL和sum <= c的时候情况。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define LL __int64
LL dp[][][];
int p[];
int main()
{
int i,j,k,u,v,n,c,s1,s2,sum;
double ans = ;
scanf("%d",&n);
sum = ;
for(i = ; i <= n; i ++)
{
scanf("%d",&p[i]);
sum += p[i];
}
scanf("%d",&c);
if(sum <= c)
{
printf("%d\n",n);
return ;
}
for(i = ; i <= n; i ++)
{
memset(dp,,sizeof(dp));
dp[][][] = ;
s1 = ;
s2 = ;
for(j = ; j <= n; j ++)
{
if(i == j) continue;
for(k = ; k < j; k ++)
{
for(u = ; u <= ; u ++)
dp[s2][k][u] = dp[s1][k][u];
}
for(k = ; k < j; k ++)
{
for(u = ; u < ; u ++)
{
if(dp[s1][k][u])
{
if(u+p[j] <= )
dp[s2][k+][u+p[j]] += dp[s1][k][u];
}
}
}
swap(s1,s2);
}
for(j = ; j < c; j ++)
{
if(j + p[i] >= c)
{
for(k = ; k < n; k ++)
{
if(dp[s1][k][j] == ) continue;
double temp = dp[s1][k][j];
for(u = ,v = k+;u <= n-k-;u ++,v++)
temp *= u*1.0/v;
temp /= n;
if(j + p[i] == c)
ans += temp*(k+);
else
ans += temp*k;
}
}
}
}
printf("%lf\n",ans);
return ;
}
Codeforces Round #160 (Div. 2) D. Maxim and Restaurant(DP)的更多相关文章
- Codeforces Round #160 (Div. 1) 题解【ABCD】
Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...
- Codeforces Round #622 (Div. 2) A. Fast Food Restaurant(全排列,DFS)
Codeforces Round #622 (Div. 2) A. Fast Food Restaurant 题意: 你是餐馆老板,虽然只会做三道菜,上菜时还有个怪癖:一位客人至少上一道菜,且一种菜最 ...
- Codeforces Round #367 (Div. 2) C. Hard problem(DP)
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...
- Codeforces Round #160 (Div. 2)
A. Roma and Lucky Numbers 暴力计算. B. Roma and Changing Signs 每次取最小值改变正负,优先队列维护. C. Maxim and Discounts ...
- Codeforces Round #374 (Div. 2) D. Maxim and Array 贪心
D. Maxim and Array 题目连接: http://codeforces.com/contest/721/problem/D Description Recently Maxim has ...
- Codeforces Round #374 (Div. 2) D. Maxim and Array —— 贪心
题目链接:http://codeforces.com/problemset/problem/721/D D. Maxim and Array time limit per test 2 seconds ...
- Codeforces Round #374 (Div. 2) D. Maxim and Array 线段树+贪心
D. Maxim and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #374 (Div. 2) D. Maxim and Array
传送门 分析:其实没什么好分析的.统计一下负数个数.如果负数个数是偶数的话,就要尽量增加负数或者减少负数.是奇数的话就努力增大每个数的绝对值.用一个优先队列搞一下就行了. 我感觉这道题的细节极为多,非 ...
- Codeforces Round #160 (Div. 2)---A. Roma and Lucky Numbers
Roma and Lucky Numbers time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- WebApiのエラーメッセージをどうカスタマイズです?
本来是发布在客户的Wiki上,所以就用日语写. ------------------------------------------------------------------------ Web ...
- linux命令**50
1.ls命令 命令格式: ls [选项] [目录名] 命令功能: 列出目标目录中所有的子目录和文件. 常用参数: -a,列出所有文件包括隐藏文件 -l,列出详细信息,文件大小一般以字节大小显示 -h, ...
- Install PIL on mac osX10.9
follow this instruction: http://blog.csdn.net/liushuaikobe/article/details/8729652 and if you encoun ...
- android 入门- 词汇
final Resources.Theme theme = context.getTheme(); TypedArray a = theme.obtainStyledAttributes();获得自定 ...
- C中的野指针—如何避免
转自:http://www.cnblogs.com/viviwind/archive/2012/08/14/2638810.html 先看一个例子: struct student{ char* nam ...
- 机器学习公开课笔记(5):神经网络(Neural Network)——学习
这一章可能是Andrew Ng讲得最不清楚的一章,为什么这么说呢?这一章主要讲后向传播(Backpropagration, BP)算法,Ng花了一大半的时间在讲如何计算误差项$\delta$,如何计算 ...
- 用PowerShell脚本删除SharePoint 的 Page中的WebPart
编写PowerShell脚本可以删除page中所有的webpart,也可以根据webpart的属性信息去删除特定的webpart. 下面的PowerShell脚本便是删除对应page中所有的webpa ...
- AndroidStudio中创建Assets文件
- ontouchstart
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta cont ...
- SQLServer 维护脚本分享(10)索引
--可添加索引的字段 migs.user_seeks,migs.avg_total_user_cost,migs.avg_user_impact,migs.last_user_seek ,mid.st ...