acdream 群赛5 组合数学
来源:互联网 发布:远程网络学历教育 编辑:程序博客网 时间:2024/06/03 07:08
Problem B: Dice Dice Dice
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 81 Solved: 17
[Submit][Status][Web Board]
Description
There are 1111 ways in which five 6-sided dice (sides numbered 1 to 6) can be rolled so that the top three numbers sum to 15. Some examples are:
D1,D2,D3,D4,D5 = 4,3,6,3,5
D1,D2,D3,D4,D5 = 4,3,3,5,6
D1,D2,D3,D4,D5 = 3,3,3,6,6
D1,D2,D3,D4,D5 = 6,6,3,3,3
Now we have a extended problem:
In how many ways can n m-sided dice (sides numbered 1 to m) be rolled so that the top k numbers sum to p?
Input
There are multiple test cases. (about 15 groups)
For each test case, there is only four integers n, m, k, p. (1 <= k <= n <= 20, 3 <= m <= 12)
Output
For each test case, output an integer indicating the answer.
Sample Input
5 6 3 156 6 3 15
Sample Output
11117770
HINT
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <queue>#include <cmath>#include <stack>#include <map> using namespace std;#define LL long longint n,m,k,p;int re[109];LL ans;LL N(int t){ LL ret = 1; for(int i=2;i<=t;i++) ret*=i; return ret;}void dfs(int t,int lim){ if(t<k){ for(int i=lim;i>0;i--) { re[t] = i; dfs(t+1,i); } }else if(t==k){ int s = 0; for(int i=0;i<k;i++) s+=re[i]; if(s!=p) return ; // for(int i=0;i<k;i++) // cout<<re[i]<<" ";cout<<endl; if(k<n) for(int i=lim;i>0;i--) { re[t] = i; dfs(t+1,i); } else { re[n]=lim; dfs(t+1,lim); } return ; }else if(t>k&&t<n) { for(int i=lim;i>0;i--) { re[t] = i; dfs(t+1,i); } return ; } if(t>=n){ LL tmp = N(n); // cout<<"con:"<<endl; // for(int i=0;i<n;i++) // cout<<re[i]<<" ";cout<<endl; // cout<<tmp<<endl; int c=1; re[n] = -1; for(int i=1;i<=n;i++) { if(re[i]!=re[i-1]) { tmp/=N(c); c=1; } else c++; } ans+=tmp; return ; }}int main(){ // freopen("in.txt","r",stdin); while(~scanf("%d%d%d%d",&n,&m,&k,&p)) { // cout<<"<<<<<<<<<<<"<<endl; ans = 0; dfs(0,m); cout<<ans<<endl; } return 0;}
- acdream 群赛5 组合数学
- acdream 1686(数学)
- acdream 1077(数学)
- ACdream 1213 简单数学
- 组合数学
- 组合数学
- 组合数学
- 组合数学
- 组合数学
- 组合数学
- 组合数学
- 组合数学
- 组合数学
- 组合数学
- 组合数学
- 组合数学
- 组合数学
- 组合数学
- Ubuntu下 wine 安装与使用总结
- Qt 之路 (01)—前言
- NULL的介绍
- 自我管理&时间管理
- oracle中过程调用函数
- acdream 群赛5 组合数学
- protel99技巧总结
- Visio 2007 画大括号
- java net post 请求
- IE无法显示PNG格式图片的解决
- U1002:487-3279
- http常用响应状态码
- SQLServer中的字符串截取函数使用示例
- struts1 和struts2 的区别