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 ...
随机推荐
- Delphi中DLL的创建和使用
参考:http://blog.csdn.net/ninetowns2008/article/details/6311663 结合这篇博客:http://www.cnblogs.com/xumenger ...
- 湘潭邀请赛 Hamiltonian Path
湘潭邀请赛的C题,哈密顿路径,边为有向且给定的所有边起点小于终点,怎么感觉是脑筋急转弯? 以后一定要牢记思维活跃一点,把复杂的事情尽量简单化而不是简单的事情复杂化. #include<cstdi ...
- js特效
1.轮播换图 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- Win10 创建应用程序包及部署
https://msdn.microsoft.com/zh-cn/library/windows/apps/xaml/hh454036.aspx https://msdn.microsoft.com/ ...
- AgileEAS.NET SOA 中间件2013第四季度发布&部分功能开源预告
一.前言 AgileEAS.NET SOA 中间件平台是一款基于基于敏捷并行开发思想和Microsoft .Net构件(组件)开发技术而构建的一个快速开发应用平台.用于帮助中小型软件企业建立一条适合市 ...
- [SQL]查询及删除重复记录的SQL语句
一:查询及删除重复记录的SQL语句1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断select * from peoplewhere peopleId in (select ...
- Linggle: 英语写作学习搜索引擎
Linggle 搜索引擎是一个可用于英语写作的语法.句子工具,可帮助学习者分析更准确的英文写作建议,能够根据词性来推测短句和句子,可精准的分享出完整英文句子如何撰写. Linggle 是台湾学术团队研 ...
- JQuery初探
[TOC] jquery 通过jQuery,您可以选取(查询,query)HTML元素,并对它们执行"操作"(actions). jQuery 使用的语法是 XPath 与 CSS ...
- pythonchallenge之C++学习篇-02
第二关任然是一个字符处理的关卡 查看网页源码发现有一大串字符需要处理,这么多的字符如果放在源代码里就很不好了 所以要用到C++对文件的操作,用到的头文件是fstream 这里参照了这个博文 对文件处理 ...
- Java学习笔记(三)——运算符
一.运算符: 1.分类: 2.java中的运算符 (1)其中,++在左,表示先加了再用,++在右,表示先用了再加. (2)% 用来求余数,也称为"取模运算符" 3.赋值运算符 4. ...