zoukankan      html  css  js  c++  java
  • lightoj1064 【DP求方案】

    题意:
    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
    ",A);
            else
                printf("%lld/%lld
    ",A,B);
        }
        return 0;
    }
    
    
    



  • 相关阅读:
    git将已存在的项目转换成git项目&托管git服务器
    联合索引
    MyISAM和InnoDb的关系
    NPOIHelper
    C# CRC各种转换
    appcloud 微信分享大图片
    C# 微信JSSDK 获取配置信息
    简易delegate委托
    GPS、谷歌、百度、高德坐标相互转换
    反射执行方法WINFROM
  • 原文地址:https://www.cnblogs.com/keyboarder-zsq/p/6777506.html
Copyright © 2011-2022 走看看