zoukankan      html  css  js  c++  java
  • 条件DP UVA 672 Gangsters

    题目传送门

    题意:n个歹徒进饭店,可变化宽度的门,范围[0, k],每个歹徒进门在ti时间进门,身材si,进去后有pi的成功值,问最大的成功值

    分析:首先按照进门时间排序,dp[i][j] 表示第i个歹徒在门大小为j的时候进门的最大成功值,那么状态转移方程:dp[i][j] = dp[i-1][k] + a[i].p 条件是门大小从k到j的时间差小于i和ii-1人进门时间差

    收获:这类有条件限制的dp转移,我分类为条件DP

    代码:

    /************************************************
    * Author        :Running_Time
    * Created Time  :2015-8-31 16:19:35
    * File Name     :UVA_672.cpp
     ************************************************/
    
    #include <cstdio>
    #include <algorithm>
    #include <iostream>
    #include <sstream>
    #include <cstring>
    #include <cmath>
    #include <string>
    #include <vector>
    #include <queue>
    #include <deque>
    #include <stack>
    #include <list>
    #include <map>
    #include <set>
    #include <bitset>
    #include <cstdlib>
    #include <ctime>
    using namespace std;
    
    #define lson l, mid, rt << 1
    #define rson mid + 1, r, rt << 1 | 1
    typedef long long ll;
    const int N = 1e2 + 10;
    const int INF = 0x3f3f3f3f;
    const int MOD = 1e9 + 7;
    struct People   {
        int t, p, s;
        bool operator < (const People &r) const {
            return t < r.t;
        }
    }a[N];
    int dp[N][N];
    
    int main(void)    {
        int T;  scanf ("%d", &T);
        while (T--) {
            int n, door, time;  scanf ("%d%d%d", &n, &door, &time);
            for (int i=1; i<=n; ++i)    scanf ("%d", &a[i].t);
            for (int i=1; i<=n; ++i)    scanf ("%d", &a[i].p);
            for (int i=1; i<=n; ++i)    scanf ("%d", &a[i].s);
            sort (a+1, a+1+n);
            
            memset (dp, -1, sizeof (dp));
            int ans = 0;    dp[0][0] = 0;
            for (int i=1; i<=n; ++i)    {
                for (int j=0; j<=door; ++j) {
                    for (int k=0; k<=door; ++k) {
                        if (dp[i-1][k] == -1 || abs (j - k) > a[i].t - a[i-1].t)   continue;
                        if (a[i].s == j && j)   {
                            dp[i][j] = max (dp[i][j], dp[i-1][k] + a[i].p);
                        }
                        else    {
                            dp[i][j] = max (dp[i][j], dp[i-1][k]);
                        }
                        ans = max (ans, dp[i][j]);
                    }
                }
            }
            printf ("%d
    ", ans);
            if (T)  puts ("");
        }
    
        return 0;
    }
    

      

    编译人生,运行世界!
  • 相关阅读:
    如何使用Jquery 引入css文件
    html如何绘制带尖角(三角)的矩形
    让HTML标签、DIV、SPAN拥有focus事件和blur事件,聚焦和失焦
    html如何引用另一个html的内容
    HTML中块级元素与内联元素有什么区别 ?
    一个js文件如何加载另外一个js文件
    在线工具-程序员的工具箱-在线Cron表达式生成器
    oracle fm格式化
    html如何让label在div中的垂直方向居中显示?
    服务发现框架选型: Consul、Zookeeper还是etcd ?
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4773958.html
Copyright © 2011-2022 走看看