zoukankan      html  css  js  c++  java
  • HDU 1203 I NEED A OFFER!【01背包】

    大意:01背包

    分析:01背包

    代码:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 using namespace std;
     5 
     6 const int maxn = 10005;
     7 const int INF = 1000000000;
     8 
     9 double dp[maxn];
    10 int cost[maxn];
    11 double prob[maxn];
    12 int main() {
    13     int n, m;
    14     while(scanf("%d %d",&n, &m)  && ( n + m ) ) {
    15         for(int i = 1; i <= m; i++) {
    16             scanf("%d %lf",&cost[i], &prob[i]);
    17         }
    18         for(int i = 0; i <= n; i++) dp[i] = 1.0;
    19         for(int i = 1; i <= m; i++) {
    20             for(int j = n; j >= cost[i]; j--) {
    21                 dp[j] = min(dp[j], dp[j - cost[i]] * (1.0 - prob[i]));
    22             }
    23         }
    24         double ans = 1.0 -  dp[n];
    25         ans *= 100;
    26         printf("%.1lf%%
    ",ans);
    27     }
    28     return 0;
    29 }
    View Code
  • 相关阅读:
    尚未笔记知识点
    jsonp的原理及其使用
    django中将views.py中的python方法传递给html模板文件
    UVA
    UVA
    UVA
    UVA
    UVA
    UVA 1600 Patrol Robot
    UVA
  • 原文地址:https://www.cnblogs.com/zhanzhao/p/3945833.html
Copyright © 2011-2022 走看看