Advertisement
Saleh127

Light OJ 1064 / DP - Probability

Aug 26th, 2022
962
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. /***
  2.  created: 2022-08-27-02.11.17
  3. ***/
  4.  
  5. #include <bits/stdc++.h>
  6. #include <ext/pb_ds/assoc_container.hpp>
  7. #include <ext/pb_ds/tree_policy.hpp>
  8. using namespace std;
  9. using namespace __gnu_pbds;
  10. template<typename U> using ordered_set=tree<U, null_type,less<U>,rb_tree_tag,tree_order_statistics_node_update>;
  11. #define ll long long
  12. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  13. #define get_lost_idiot return 0
  14. #define nl '\n'
  15.  
  16. ll dp[27][6*25 + 5];
  17. ll n,x;
  18.  
  19. ll solve(ll in, ll sum)
  20. {
  21.     if(in>=n)
  22.     {
  23.         return sum>=x;
  24.     }
  25.  
  26.     if(dp[in][sum]!=-1) return dp[in][sum];
  27.  
  28.     ll ans=0;
  29.  
  30.     for(ll i=1;i<=6;i++)
  31.     {
  32.         ans+=solve(in+1,sum+i);
  33.     }
  34.  
  35.     return dp[in][sum]=ans;
  36. }
  37.  
  38. int main()
  39. {
  40.     ios_base::sync_with_stdio(0);
  41.     cin.tie(0);
  42.     cout.tie(0);
  43.  
  44.     test
  45.     {
  46.         ll p,q,i,j,k,l;
  47.  
  48.         cin>>n>>x;
  49.  
  50.         memset(dp,-1,sizeof dp);
  51.  
  52.         p=solve(0,0);
  53.         q=pow(6,n);
  54.  
  55.         l=__gcd(p,q);
  56.  
  57.         p/=l,q/=l;
  58.  
  59.         cout<<"Case "<<cs<<": "<<p;
  60.  
  61.         if(q>1) cout<<"/"<<q<<nl;
  62.         else cout<<nl;
  63.  
  64.     }
  65.  
  66.  
  67.  
  68.     get_lost_idiot;
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement