zoukankan      html  css  js  c++  java
  • HDU 4815 Little Tiger vs. Deep Monkey(2013长春现场赛C题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4815

    简单的DP题。

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <iostream>
     4 #include <algorithm>
     5 #include <queue>
     6 #include <map>
     7 #include <set>
     8 #include <vector>
     9 #include <string>
    10 #include <math.h>
    11 using namespace std;
    12 const int MAXN = 40010;
    13 double dp[2][MAXN];
    14 int a[MAXN];
    15 int main()
    16 {
    17     //freopen("in.txt","r",stdin);
    18     //freopen("out.txt","w",stdout);
    19     int n;
    20     int T;
    21     double P;
    22     scanf("%d",&T);
    23     while(T--)
    24     {
    25         scanf("%d%lf",&n,&P);
    26         int sum = 0;
    27         for(int i = 0;i < n;i++)
    28         {
    29             scanf("%d",&a[i]);
    30             sum += a[i];
    31         }
    32         memset(dp,0,sizeof(dp));
    33         int now = 0;
    34         dp[now][0] = 1;
    35         for(int i = 0;i < n;i++)
    36         {
    37             now ^= 1;
    38             memset(dp[now],0,sizeof(dp[now]));
    39             for(int j = 0 ;j <= sum;j++)
    40                 if(dp[now^1][j] > 0)
    41                 {
    42                     dp[now][j+a[i]] += 0.5*dp[now^1][j];
    43                     dp[now][j] += 0.5*dp[now^1][j];
    44                 }
    45         }
    46         for(int i = 1;i <= sum;i++)
    47             dp[now][i] += dp[now][i-1];
    48         int ans = 0;
    49         for(int i = 0;i <= sum;i++)
    50             if(dp[now][i] >= P)
    51             {
    52                 ans = i;
    53                 break;
    54             }
    55         printf("%d
    ",ans);
    56     }
    57     return 0;
    58 }
  • 相关阅读:
    LeetCode90.子集 ||
    Ubuntu下的Matlab安装
    FAQ
    青石板
    交叉熵损失函数
    tf常用函数
    激活函数
    SGD和GD的区别
    卷积神经网络
    Ubuntu安装Matlab2016b
  • 原文地址:https://www.cnblogs.com/kuangbin/p/3506465.html
Copyright © 2011-2022 走看看