• 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;
    }
    

      

  • 相关阅读:
    一个非常棒的jQuery 评分插件好东西要分享
    Visual Studio 2012 更新包2发布,附离线安装方法及下载
    ECC Copy Client 之后的SAP*登陆问题 沧海
    使用现有ECC数据库进行安装或者恢复系统 沧海
    SAP 登陆平衡(SAP Logon Balancing) 沧海
    Target host or target server ***** is not in operation mode 沧海
    如何获得系统设置参数列表 沧海
    IDES安装之后的配置 沧海
    关于Basware的使用随想 沧海
    Information About the SAP Load Generator (SGEN) 沧海
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/7475237.html
Copyright © 2020-2023  润新知