题目大意:

n个人进入商店买东西,对于每个顾客都有T、C、P这3个数组,表示有Pj的概率第i个顾客在Tj的时间进入商店以Cj的价格买东西,每个顾客Pj的和小于等于1,保证每个时间只最多只有一个顾客可能会来,每个顾客只进入商店一次。一共有swords个物品,当一个顾客进来买东西的时候,售货员可以选择卖或不卖,她以之后的最大期望进行选择。问收银额的期望是多少。

解题思路:

当每个顾客可能来商店的时间只有一个的时候,题目比较简单,用dp[时间][剩下物品个数]的dp方程就可以解决。

当有顾客可能来商店的时间超过一个的时候,情况有点复杂,因为计算到下一个时间的时候,该顾客会不会出现的概率跟之前他有没有出现有关:如果之前他出现过了,那么这个时刻该顾客出现的概率为0;如果他之前没出现过,那个这个时间该顾客出现的概率是条件概率=原本的概率/(1-之前出现的概率和)。于是用一个位压缩状态来保存之前该顾客有没有出现。由于可能来商店的时间超过一个的顾客数量最多是24/2=12个,这样可以减少空间和时间。

之前没意识到这个是条件概率,一下子懵了,囧。。。。。

// BEGIN CUT HERE
#include <sstream>
/*
*/
#define debuging
#ifdef debuging
#define FIN {freopen("new.in" , "r" , stdin) ;}
#define FOUT {freopen("new.out" , "w" , stdout) ;}
#define OUT(x) {cout<< #x << " : " << x <<endl ;}
#define ERR(x) {cout<<"#error: "<< x ; while(1) ;}
#endif
// END CUT HERE
#ifndef debuging
#define FIN ;
#define FOUT ;
#define OUT(x) ;
#define ERR(x) ;
#endif
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
using namespace std ;
#define For(i , n) for(int i = 0 ; i < (n) ; ++i)
#define SZ(x) (int)((x).size())
#define clr(a,b) memset(a,b,sizeof(a))
#define mpr(a,b) make_pair(a,b)
typedef long long lint ;
const int maxint = -1u>> ;
const double eps = 1e- ; double dp[<<][][]; class NewItemShop
{
public:
int peo[],cost[];double p[];
char str[];int sw;
int sam[]; double dfs(int mask,int swords,int tim){
double &s=dp[mask][swords][tim];
if(s>-0.5)return s;
if(tim==||swords==)return s=;
if(peo[tim]==-)return s=dfs(mask,swords,tim+);
if(peo[tim]==-){
s=p[tim]*max(dfs(mask,swords-,tim+)+cost[tim],dfs(mask,swords,tim+));
s+=(-p[tim])*dfs(mask,swords,tim+);
return s;
}else{
if(!(mask&(<<peo[tim])))return s=dfs(mask,swords,tim+);
s=p[tim]*max(dfs(mask^(<<peo[tim]),swords-,tim+)+cost[tim],dfs(mask^(<<peo[tim]),swords,tim+));
s+=(-p[tim])*dfs(mask,swords,tim+);
return s;
}
} double getMaximum(int swords, vector <string> customers)
{
clr(peo,-);sw=swords;
int n=customers.size();
int cnt=;
for(int i=;i<n;i++){
string s=customers[i];
int now=;double tmp=;sam[i]=;
vector<int>vec;vec.clear();
while(now<(int)s.size()){
int a,b;double c;
int k=;
while(now<(int)s.size()&&s[now]!=' '){
str[k]=s[now];k++;now++;
}
now++;
str[k]=;
sscanf(str,"%d,%d,%lf",&a,&b,&c);
peo[a]=i;cost[a]=b;p[a]=c//tmp;
tmp-=c/;
vec.push_back(a);
}
if(vec.size()==){
peo[vec[]]=-;
}else{
for(int i=;i<(int)vec.size();i++)
peo[vec[i]]=cnt;
cnt++;
}
}
for(int i=;i<<<cnt;i++)
for(int j=;j<=swords;j++)
for(int k=;k<=;k++)
dp[i][j][k]=-;
double ans=dfs((<<cnt)-,swords,);
return double(ans) ;
}
};

SRM 515 DIV1 550pt的更多相关文章

  1. topcoder srm 515 div1

    problem1 link 暴力枚举即可. problem2 link 一共有24小时,所以最多有24个顾客.设$f[x][y][z]$表示还剩下$x$把刀,现在时间是$y$,以及来过的顾客集合为$z ...

  2. Topcoder SRM 643 Div1 250<peter_pan>

    Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...

  3. Topcoder Srm 726 Div1 Hard

    Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...

  4. 图论 SRM 674 Div1 VampireTree 250

    Problem Statement      You are a genealogist specializing in family trees of vampires. Vampire famil ...

  5. SRM 449 div1 (practice)

    250pt: 暴力枚举所有的可能的情况就好了,求面积的时候我是用梯形的面积减去两个三角形的面积.. 550pt: 题意:给你一个蜂窝形状的特殊图形,有一些格子已经被占据了,问你将剩下的格子用1*2的砖 ...

  6. SRM 583 DIV1

    A 裸最短路. class TravelOnMars { public: int minTimes(vector <int>, int, int); }; vector<int> ...

  7. SRM 590 DIV1

    转载请注明出处,谢谢viewmode=contents">http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlov ...

  8. Topcoder SRM 602 div1题解

    打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...

  9. 状态压缩DP SRM 667 Div1 OrderOfOperations 250

    Problem Statement      Cat Noku has just finished writing his first computer program. Noku's compute ...

随机推荐

  1. log4net配置,正在用

    <?xml version="1.0" encoding="utf-8" ?> <log4net> <appender name= ...

  2. display:inline、block、inline-block的区别 摘】

    display:block就是将元素显示为块级元素. block元素的特点是: 总是在新行上开始: 高度,行高以及顶和底边距都可控制: 宽度缺省是它的容器的100%,除非设定一个宽度 <div& ...

  3. [ CodeVS冲杯之路 ] P1501

     不充钱,你怎么AC? 题目:http://codevs.cn/problem/1501/ 水题一道 直接dfs,记录上当前深度,到了叶子节点就更新答案,并且每个节点将当前深度的计数+1,答案即为ma ...

  4. vue elementui 递归 sidebar可伸缩侧边栏

    最近在学习vue 做了一个可伸缩的 侧边栏 记录下 在很多管理系统都用到 管理系统一般都长的差不多 首先是收起时候 展开时候 首先是新建一个Layout.vue <template> &l ...

  5. JS操作checkBox

    代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w ...

  6. linux系统查看主机序列号

    #dmidecode -t 1 System Information        Manufacturer: IBM        Product Name: System x3650 M3 -[7 ...

  7. 【Android开发日记】之入门篇(三)——Android目录结构

    本来的话,这一章想要介绍的是Android的系统架构,毕竟有了这些知识的储备,再去看实际的项目时才会更清楚地理解为什么要这样设计,同时在开发中遇到难题,也可以凭借着对Android的了解,尽快找出哪些 ...

  8. 51nod 1432 独木舟【贪心】

    1432 独木舟 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题  收藏  关注 n个人,已知每个人体重.独木舟承重固定,每只独木舟最多坐两个人,可以坐一个人或者两 ...

  9. csu1811(树上启发式合并)

    csu1811 题意 给定一棵树,每个节点有颜色,每次仅删掉第 \(i\) 条边 \((a_i, b_i)\) ,得到两颗树,问两颗树节点的颜色集合的交集. 分析 转化一下,即所求答案为每次删掉 \( ...

  10. spring jpa data笔记

    tomcat启动Maven项目的时候总抛出这样的错误: Error creating bean with name 'org.springframework.boot.autoconfigure.or ...