1. 程式人生 > >dp hdu5653 xiaoxin and his watermelon candy

dp hdu5653 xiaoxin and his watermelon candy

n) algorithm 控制 put define ace ati max -s

傳送門:點擊打開鏈接

題意:有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\n", floor(dp[n] * W));
    }
}


dp hdu5653 xiaoxin and his watermelon candy