zoukankan      html  css  js  c++  java
  • HDU 5781 ATM Mechine (期望DP)

    题意:你有一些钱数量在 0 ~ n 之间,然后你要取钱,但是如果取的钱数超过你的钱数,会被警告,问警告不超过m次,把钱取走的期望是多少。

    析:dp[i][j]  表示钱在 0 ~ i,然后最多 j 次警告,根据二分的思想,j 最大是11,然后每次取 k 元,分为两种情况,一种是钱数不小于k,那么就会被警告,就会转移到 dp[k-1][j-1],如果线数不小于k,那么转移到 dp[i-k][j]。

    代码如下:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <cmath>
    #include <stack>
    #include <sstream>
    #include <list>
    #include <assert.h>
    #include <bitset>
    #define debug() puts("++++");
    #define gcd(a, b) __gcd(a, b)
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define fi first
    #define se second
    #define pb push_back
    #define sqr(x) ((x)*(x))
    #define ms(a,b) memset(a, b, sizeof a)
    #define sz size()
    #define pu push_up
    #define pd push_down
    #define cl clear()
    #define all 1,n,1
    #define FOR(x,n)  for(int i = (x); i < (n); ++i)
    #define freopenr freopen("in.txt", "r", stdin)
    #define freopenw freopen("out.txt", "w", stdout)
    using namespace std;
    
    typedef long long LL;
    typedef unsigned long long ULL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 1e20;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 2000 + 10;
    const LL mod = 1e9 + 7;
    const int dr[] = {-1, 0, 1, 0};
    const int dc[] = {0, 1, 0, -1};
    const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
    int n, m;
    const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    inline bool is_in(int r, int c) {
      return r > 0 && r <= n && c > 0 && c <= m;
    }
    
    int dp[maxn][15];
    
    void init(){
      ms(dp, INF);  ms(dp[0], 0);
      for(int i = 1; i < maxn; ++i)
        for(int j = 1; j < 12; ++j)
          for(int k = 1; k <= i; ++k)
            dp[i][j]= min(dp[i][j], dp[i-k][j] + dp[k-1][j-1] + 1 + i);
    }
    
    int main(){
      init();
      while(scanf("%d %d", &n, &m) == 2)
        printf("%.6f
    ", dp[n][min(11, m)] / (n + 1.0));
    
      return 0;
    }
    

      

  • 相关阅读:
    SpringBoot2.1.6 整合CXF 实现Webservice
    一次线上CPU高的问题排查实践
    SpringBoot整合升级Spring Security 报错 【The request was rejected because the URL was not normalized】
    Web服务器☞Apache VS Nginx
    PHP 遍历一个文件夹下所有文件和子文件夹的方法
    PHP 使用 header 方式实现文件下载功能
    PHP gd 库添加 freetype
    MySQL varchar 最大长度,text 类型占用空间剖析
    S.O.L.I.D: PHP 面向对象设计的五个基准原则
    PHP不重新编译,单独添加模块扩展的方法
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/7475237.html
Copyright © 2011-2022 走看看