lightoj1064 【DP求方案】

69 篇文章 0 订阅
题意:
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;
}





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值