lightoj - 1064 - Throwing Dice - dp / 概率dp
来源:互联网 发布:淘宝重复铺货处罚 编辑:程序博客网 时间:2024/05/16 06:05
题意:有n个骰子,求他们的和至少为x的概率。
题解:用dp统计所有情况,设dp[i][j]为到第i个骰子时,和为j的情况有多少种,则转移为dp[i][j] = sum(dp[i][j-k]),注意边界。而扔n个骰子共有6^n种情况,所以概率为sum(dp[n-1][j], j大于等于x) / 6^n 。
#include <bits/stdc++.h>//#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;#define ll long long#define SZ(x) ((int)(x).size()) #define ALL(v) (v).begin(), (v).end()#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)#define reveach(i, v) for (__typeof((v).rbegin()) i = (v).rbegin(); i != (v).rend(); ++ i) #define REP(i,a,n) for ( int i=a; i<int(n); i++ )#define FOR(i,a,n) for ( int i=n-1; i>= int(a);i-- )#define lson rt<<1, L, m#define rson rt<<1|1, m, Rtypedef pair<int, int> pii;typedef pair<ll, ll> pll;#define mp(x, y) make_pair(x, y)#define pb(x) push_back(x)#define fi first#define se second#define CLR(a, b) memset(a, b, sizeof(a))#define Min(a, b) a = min(a, b)#define Max(a, b) a = max(a, b)const int maxn = 200;int T;int kase;int n, x;ll dp[30][maxn];ll pw[25];void ini(){ REP(j, 1, 7) dp[0][j] = 1; REP(i, 1, 30){ REP(j, i + 1, i + 6){ REP(k, 1, j - i + 1){ dp[i][j] += dp[i-1][j-k]; } } REP(j, i + 6, maxn){ REP(k, 1, 7){ dp[i][j] += dp[i-1][j-k]; } } } pw[0] = 1; REP(i, 1, 25) pw[i] = pw[i-1] * 6;}int main(){#ifdef ac freopen("in.txt","r",stdin);#endif //freopen("out.txt","w",stdout); ini(); scanf("%d", &T); while(T--){ scanf("%d%d", &n, &x); ll res = 0; REP(j, x, maxn){ res += dp[n-1][j]; } ll t = __gcd(res, pw[n]); printf("Case %d: ", ++ kase); if(pw[n] / t == 1) printf("%lld\n", res / t); else printf("%lld/%lld\n", res / t, pw[n] / t); } return 0;}
0 0
- lightoj - 1064 - Throwing Dice - dp / 概率dp
- LightOJ 1064 Throwing Dice 概率DP
- LightOJ 1064 - Throwing Dice(概率DP)
- LightOj 1064 Throwing Dice(概率dp)
- LightOJ 1064 Throwing Dice (DP)
- 【LightOJ 1064 】Throwing Dice + dp
- LightOJ 1064 - Throwing Dice (dp)
- lightoj 1064 - Throwing Dice 简单DP
- Light oj 1064 Throwing Dice (概率dp)
- 【LightOJ】1064 - Throwing Dice(dp打表)
- UVa 10759 Dice Throwing (概率DP)
- UVA 10759 Dice Throwing(dp 概率)
- LightOJ 1064 Throwing Dice
- lightoj 1064 - Throwing Dice
- lightOJ 1248 - Dice (III) 概率DP
- 【LightOJ 1248】Dice (III)(概率DP)
- Light OJ 1064 Throwing Dice(简单DP)
- UVa 10759 - Dice Throwing (概率DP+预处理)
- 快速存档表数据
- 编程语言Rubyの基础入门
- Uva 12663 High bridge, low bridge 离散化
- 第五章项目1——(3)三角形类雏形
- ps笔记01-软件界面介绍
- lightoj - 1064 - Throwing Dice - dp / 概率dp
- jQuery选择器
- osx下配置qt开发环境
- 1003
- HDP 2.4安装
- JSP proxool+mysql数据库连接池配置
- 选择问题-第k小元素
- 梳理caffe代码layer_factory(六)
- mysql中<>与null值不能比较