[Bzoj3193] [JLOI2013] Terrain generate permutations _ _ greedy

[JLOI2013] terrain generation

Topic links : https://www.lydsy.com/JudgeOnline/problem.php?id=3193


Problem solution :

This arrangement required a total of the title, one conventional approach is that all the elements are arranged according to a certain manner and then inserted inside a a.

The problem is sorted in descending order like this has no effect on the elements behind.

There are a number of elements equal to how we get?

If the label is a sequence of words is blind $ jb $ row on the line.

If the contour is the sequence, so long as the $ A $ in accordance with the second keyword like.

Code :

#include <bits/stdc++.h>

#define N 1010 

using namespace std;

const int mod = 2011 ;

char *p1, *p2, buf[100000];

#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1 ++ )

int rd() {
    int x = 0, f = 1;
    char c = nc();
    while (c < 48) {
        if (c == '-')
            f = -1;
        c = nc();
    }
    while (c > 47) {
        x = (((x << 2) + x) << 1) + (c ^ 48), c = nc();
    }
    return x * f;
}

struct Node {
    int h, rk;
}a[N];

int dp[N];

inline bool cmp(const Node &a, const Node &b) {
    return a.h == b.h ? a.rk < b.rk : a.h > b.h;
}

int main() {
    int n = rd();
    for (int i = 1; i <= n; i ++ ) {
        a[i].h = rd(), a[i].rk = rd() - 1;
    }
    int ans1 = 1, ans2 = 1;
    sort(a + 1, a + n + 1, cmp);
    for (int i = 1; i <= n; i ++ ) {
        int dic = i;
        while (dic <= n && a[dic].h == a[i].h) {
            dic ++ ;
        }
        dic -- ;
        memset(dp, 0, sizeof dp);
        dp[0] = 1;
        for (int j = i; j <= dic; j ++ ) {
            ans1 = ans1 * (min(i, a[j].rk + 1) + j - i) % mod;
            for (int k = 1; k <= min(a[j].rk, i - 1); k ++ ) {
                dp[k] = (dp[k - 1] + dp[k]) % mod;
            }
        }
        int sum = 0;
        for (int j = 0; j <= min(a[dic].rk, i - 1); j ++ ) {
            (sum += dp[j]) %= mod;
        }
        (ans2 *= sum) %= mod;
        i = dic;
    }
    cout << ans1 << ' ' << ans2 << endl ;
    return 0;
}

Summary : Remember, to consider the issue when the current time stamp that is easy to overlook the variables taken into account, even though most of the time with less.

Guess you like

Origin www.cnblogs.com/ShuraK/p/11431422.html