SuitNdtie

Bond100

May 20th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int n;
  4.  
  5. double value[20][20];
  6.  
  7. double max(double a,double b){
  8.     return (a > b ? a : b);
  9. }
  10.  
  11. /*
  12. double cal(int order,int check){
  13.     if(check == (1<<n)-1){
  14.         return 1;
  15.     }
  16.     double ans = 0;
  17.     for(int i = 0 ; i < n ; i ++){
  18.         if((check & (1<<i)) == 0){ //and use
  19.             ans = max(ans,cal(order+1,(check | (1<<i)))*(value[i][order]/100)    );
  20.         }
  21.     }
  22.     return ans;
  23. }
  24. */
  25. int main()
  26. {
  27.     scanf("%d",&n);
  28.     for(int i = 0 ; i < n ; i ++){
  29.         for(int j = 0 ; j < n ; j ++){
  30.             scanf("%lf",&value[i][j]);
  31.         }
  32.     }
  33.     double dp[1<<n];
  34.    
  35.     for(int check = (1<<n)-1 ; check >= 0 ; check --){
  36.         int order = __builtin_popcount(check);
  37.         if(check == (1<<n)-1 || order == n){
  38.             dp[check] = 1;
  39.             continue;
  40.         }
  41.         double ans = 0;
  42.         for(int i = 0 ; i < n ; i ++){
  43.             if((check & (1<<i)) == 0){ //and use
  44.                 double d;
  45.                 if(order+1 == n){
  46.                     d = 1;
  47.                 }
  48.                 else{
  49.                     d = dp[(check | (1<<i))];
  50.                 }
  51.                 ans = max(ans,d * (value[i][order]/100));
  52.             }
  53.         }
  54.         dp[check] = ans;
  55.     }
  56.     printf("%lf",dp[0]*100);
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment