题意:
n个相同的骰子,问你掷出>=x点数的可能性;
思路:
dp[i][j]代表前 i 个骰子掷出 j 点数的方案数;
n个相同的骰子,问你掷出>=x点数的可能性;
思路:
dp[i][j]代表前 i 个骰子掷出 j 点数的方案数;
然后Σdp[n][x]-dp[n][6*n]就好了
卧槽,一开始想的是拆分搞。。。。。。其实这种就是个简单DP啊///
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>PII;
const double eps=1e-5;
const double pi=acos(-1.0);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
LL f[30];
LL dp[30][155];
void init()
{
f[0]=1;
for(int i=1;i<25;i++)
f[i]=f[i-1]*6;
memset(dp,0,sizeof(dp));
dp[0][0]=1;
for(int i=1;i<=6;i++)
dp[1][i]=1;
for(int i=2;i<=24;i++)
for(int j=1;j<=i*6;j++)
for(int k=1;k<=6&&k<j;k++)
dp[i][j]+=dp[i-1][j-k];
}
int main()
{
init();
int n,x,T,cas=1;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&x);
printf("Case %d: ",cas++);
LL ans=0;
for(int i=x;i<=n*6;i++)
ans+=dp[n][i];
if(x>n*6)
{
puts("0");
continue;
}
LL A=ans;
LL B=f[n];
LL gcd=__gcd(A,B);
A/=gcd;
B/=gcd;
if(A%B==0)
printf("%lld\n",A);
else
printf("%lld/%lld\n",A,B);
}
return 0;
}