每日一题 6.24 小A买彩票

小A买彩票

https://ac.nowcoder.com/acm/problem/23413

二维dp 一维总数 二维总钱数
求出能过的答案数后 求总方案数 求两者的公因子

#include <bits/stdc++.h>
#define ll long long
int const N=35;
using namespace std;
ll n,dp[N][N<<2],ans;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    dp[0][0]=1;
    for(int i=1;i<=n;++i)
    {
        for(int j=i;j<=i<<2;++j)
        {
            for(int k=1;k<=4;++k)
            {
                if(j<k) break;
                dp[i][j]+=dp[i-1][j-k];
            }
        }
    }
    for(int i=n*3;i<=n<<2;++i) ans+=dp[n][i];
    ll b=powl(4,n);
    ll c=__gcd(ans,b);
    cout<<ans/c<<"/"<<b/c<<endl;
    return 0;
}
每日一题题解 文章被收录于专栏

每日一题题解的汇集

全部评论

相关推荐

一表renzha:手写数字识别就是一个作业而已
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务