• dp hdu5653 xiaoxin and his watermelon candy


    传送门:点击打开链接

    题意:有n个箱子排成一排,有m个炸弹。位置告诉你。如今炸弹的左边伤害和右边伤害能够自己控制,要求 每一个炸弹炸的箱子数的累乘,输出答案取log2并乘以1e6

    思路:直接2for xjb搞即可了。大概就是某个区间里刚好仅仅有一个炸弹时,就是满足的,然后就从前面往后面更新一下

    #include <map>
    #include <set>
    #include <cmath>
    #include <ctime>
    #include <stack>
    #include <queue>
    #include <cstdio>
    #include <cctype>
    #include <string>
    #include <vector>
    #include <cstring>
    #include <iomanip>
    #include <iostream>
    #include <algorithm>
    #include <functional>
    #define fuck(x) cout<<"["<<x<<"]"
    #define FIN freopen("input.txt","r",stdin)
    #define FOUT freopen("output.txt","w+",stdout)
    using namespace std;
    typedef long long LL;
    typedef pair<int, int> PII;
    
    const int MX = 2e3 + 5;
    const int W = 1e6;
    
    int A[MX];
    double dp[MX];
    
    int main() {
        int T, n, m; //FIN;
        scanf("%d", &T);
        while(T--) {
            scanf("%d%d", &n, &m);
            memset(A, 0, sizeof(A));
            memset(dp, 0, sizeof(dp));
    
            for(int i = 1; i <= m; i++) {
                int t; scanf("%d", &t);
                t++; A[t] = 1;
            }
            for(int i = 2; i <= n; i++) A[i] += A[i - 1];
            for(int i = 1; i <= n; i++) {
                for(int j = 0; j < i; j++) {
                    if(A[i] - A[j] == 1) {
                        dp[i] = max(dp[i], dp[j] + log2(1.0 * i - j));
                    }
                }
            }
            printf("%.0f
    ", floor(dp[n] * W));
        }
    }


  • 相关阅读:
    Django 登录页面重定向
    python 调试命令
    错误
    错误
    图算法之图的创建
    Git 常用命令详解(三)
    Git 常用命令详解(二)
    如何提问
    项目常用jquery/easyui函数小结
    我是怎么发现并解决项目页面渲染效率问题的(IE调试工具探查器的使用)
  • 原文地址:https://www.cnblogs.com/zhchoutai/p/8328505.html
Copyright © 2020-2023  润新知