【每日一题】小A买彩票
小A买彩票
https://ac.nowcoder.com/acm/problem/23413
题意:
思路:
#include <cstdio> #include <algorithm> #include <cstring> using namespace std; typedef long long ll; ll dp[35][150];//dp(i,j)表示买i张彩票获得j元的方案数 int n; ll init(){ dp[0][0] = 1; for(int i = 1;i <= n;i++){ for(int j = 1;j <= n*4;j++){ if(j) dp[i][j] += dp[i-1][j-1]; if(j-1) dp[i][j] += dp[i-1][j-2]; if(j-2) dp[i][j] += dp[i-1][j-3]; if(j-3) dp[i][j] += dp[i-1][j-4]; } } ll res = 0; for(int i = 3*n;i <= 4*n;i++){ res += dp[n][i]; } return res; } ll qpow(ll a,ll b){ ll res = 1; while(b){ if(b&1) res = res * a; a = a * a; b >>= 1; } return res; } int main(){ scanf("%d",&n); ll all = qpow(4,n); ll res = init(); ll d = __gcd(all,res); all/=d,res/=d; printf("%lld/%lld\n",res,all); return 0; }
每日一题 文章被收录于专栏
每题一题题目