Advertisement
Saleh127

Light OJ 1079 / DP-Probability (like coin change)

Aug 29th, 2022
791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. /***
  2.  created: 2022-08-30-01.23.10
  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. int main()
  17. {
  18.     ios_base::sync_with_stdio(0);
  19.     cin.tie(0);
  20.     cout.tie(0);
  21.  
  22.     test
  23.     {
  24.         ll n,m=0,i,j,k=0,l=0;
  25.  
  26.         double exp,dp[10005];;
  27.  
  28.         cin>>exp>>n;
  29.  
  30.         for(i=0;i<10002;i++) dp[i]=0.00;
  31.  
  32.         ll mn[n+4];
  33.  
  34.         double p[n+4];
  35.  
  36.         for(i=0;i<n;i++)
  37.         {
  38.             cin>>mn[i]>>p[i];
  39.             l+=mn[i];
  40.             p[i]=1.00-p[i];
  41.         }
  42.  
  43.         dp[0]=1.00;
  44.  
  45.         for(i=0;i<n;i++)
  46.         {
  47.             for(j=l;j>=mn[i];j--)
  48.             {
  49.                 if(dp[j-mn[i]]!=0)
  50.                 {
  51.                     dp[j]=max(dp[j],dp[j-mn[i]]*p[i]*1.00);
  52.                 }
  53.                 if(1.00-dp[j]<exp)
  54.                 {
  55.                     k=max(k,j);
  56.                 }
  57.             }
  58.         }
  59.  
  60.         cout<<"Case "<<cs<<": "<<k<<nl;
  61.     }
  62.  
  63.     get_lost_idiot;
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement