CodeForces Gym 101669 B - Bricks

题解:

        手动模拟可以知道其实与事件发生的先后顺序没有关系(所以从左到右枚举就好了),f[i]表示前面位置的方块已经全部落下,并且i位置以前造成了i-s[i]个空位的方案数。而num[i]表示之前决策中包含i个空位置的决策总数。

#include"bits/stdc++.h"
using namespace std;
const int MX = 1e6+7;
const int mod = 1e9+7;
int n,m;
int cnt[MX];
int f[MX],num[MX];
void upd(int &x, int y)
{
    x += y;
    if(x > mod) x-= mod;
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif // LOCAL
    scanf("%d%d",&n,&m);
    ++n;
    for(int i = 1,x; i<= m; i++){
        scanf("%d",&x);
        ++cnt[x];
    }
    for(int i = 1; i <= n; i++) cnt[i] += cnt[i-1];
    num[0] = 1;
    for(int i = 1; i <= n; i++) if(cnt[i] == cnt[i-1]){
        if(i-1-cnt[i-1] >= 0) f[i] = num[i-1-cnt[i-1]];
        if(i-cnt[i] >= 0) upd(num[i-cnt[i]],f[i]);
    }
    cout<<f[n]<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_18869763/article/details/83050405