题目大意:

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. C++自带栈与队列_stack_queue_C++

    栈和队列我们可以用C++里自带的函数使用,就不必手写了 1.栈,需要开头文件 #include<stack>  定义一个栈s:stack<int> s; 具体操作: s.emp ...

  2. OpenGL入门学习(七)(转)

    http://blog.chinaunix.net/uid-20622737-id-1912803.html 今天要讲的是OpenGL光照的基本知识.虽然内容显得有点多,但条理还算比较清晰,理解起来应 ...

  3. UVA 10910 Marks Distribution

    题意 把数字T分成N个数的和,保证这N个数中最小的数大于P.求方案数目 另f[i][j]表示把i分成j个数的和的方案数 f[i][j]=f[i][j-1]+f[i-1][j-1]+f[i-2][j-1 ...

  4. Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.Exec

    Error:Execution failed for task ':app:transformClassesWithDexForDebug'.> com.android.build.api.tr ...

  5. HDU5487 Difference of Languages(BFS)

    题意:给你两个自动机,求出最短的(如果有相同最短的则求出字典序最小的)能被其中一个自动机接收而不能被另外一个自动机接收的字符串. 一看是自动机以为是神题,后来比赛最后才有思路. 两个自动机的状态都是小 ...

  6. Fiddler抓包10-会话框添加查看get与post请求类型【转载】

    本篇转自博客:上海-悠悠 原文地址:http://www.cnblogs.com/yoyoketang/tag/fiddler/ 前言 在使用fiddler抓包的时候,查看请求类型get和post每次 ...

  7. 最近看点JAVA

    这本的书名:<求精要决:JAVA EE编程开发安全精解> 请得很懂 试一下servlet代码: <!DOCTYPE html> <html> <head> ...

  8. 51nod 1001 数组中和等于K的数对【二分查找/排序】

    1001 数组中和等于K的数对 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题  收藏  关注 给出一个整数K和一个无序数组A,A的元素为N个互不相同的整数,找出数组 ...

  9. Python的并发并行[0] -> 基本概念

    基本概念 / Basic Concept  快速跳转 进程 / Process 线程 / Thread 协程 / Coroutine 全局解释器锁 / Global Interpreter Lock ...

  10. ELK故障:elk在运行一段时间后,没有数据。

    故障排查: 1. 查看kafka.logstash.elasticsearch进程是否运行正常,显示正常. 2. 使用logstash在前台运行,有日志输出 3. 查看kafka的topic的offs ...