ARC 058

所以为啥要写来着...........

链接

 

T1 

直接枚举大于等于$n$的所有数,暴力分解判断即可

复杂度$O(10n \log n)$

#include <cstdio>
#include <iostream>
using namespace std;

#define sid 15
#define ri register int
int n, k, D[sid];

int main() {
    int x, flag;
    cin >> n >> k;
    for(ri i = 1; i <= k; i ++) { cin >> x; D[x] = 1; }
    
    for(ri i = n; i; i ++) {
        x = i; flag = 0;
        while(x) { 
            if(D[x % 10]) { flag = 1; break; }
            x /= 10;
        }
        if(!flag) 
        { printf("%d\n", i); break; }
    }
    return 0;
}

 

T2

把第$B$列单独拿出来讨论转移即可

复杂度$O(H)$

#include <cstdio>
#include <iostream>
using namespace std;

#define sid 200050
#define ri register int
#define mod 1000000007

int fac[sid], inv[sid];
int H, W, A, B;

void Init_C() {
    fac[0] = fac[1] = 1; inv[0] = inv[1] = 1;
    for(ri i = 2; i <= 200000; i ++) fac[i] = 1ll * fac[i - 1] * i % mod;
    for(ri i = 2; i <= 200000; i ++) inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
    for(ri i = 2; i <= 200000; i ++) inv[i] = 1ll * inv[i - 1] * inv[i] % mod;
}

int C(int n, int m) {
    if(m > n) return 0;
    return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod;
}

int way(int x1, int y1, int x2, int y2) {
    return C(x2 - x1 + y2 - y1, x2 - x1);
}

int main() {
    Init_C();
    cin >> H >> W >> A >> B;
    int ans = 0, sum = 0;
    for(ri i = 1; i <= H - A; i ++)
    ans = (ans + 1ll * way(1, 1, B, i) * way(B + 1, i, W, H) % mod) % mod; 
    printf("%d\n", ans);
    return 0;
}

 

 

T3

神奇状压.......

一开始没怎么想直接打了错误的$dp$....没过样例才意识到什么

正着计数不好计数,考虑反面,求解不存在连续区间和为$X, Y, Z$的数量

把$X, Y, Z$状压成为一种状态,当在末尾插入数字时,直接把状态前移,前面的数字会自动前移.....

然后暴力转移即可,复杂度$O(2^{17} * 40)$

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

#define ri register int
#define mod 1000000007

int bit[60];
int N, x, y, z;
int f[43][140005];

int main() {
    cin >> N >> x >> y >> z;
    for(ri i = 0; i <= 25; i ++) bit[i] = 1 << i;
    
    int ans = 1;
    for(ri i = 1; i <= N; i ++) 
    ans = 1ll * ans * 10 % mod;
    
    f[0][0] = 1;
    int gg = bit[z - 1] | bit[y + z - 1] | bit[x + y + z - 1];
    int lim = bit[x + y + z] - 1;

    for(ri i = 1; i <= N; i ++)
    for(ri S = 0; S <= lim; S ++)
    for(ri v = 1; v <= 10; v ++) {
        int T = (S << v) | bit[v - 1]; T &= lim;
        if((T & gg) != gg) f[i][T] = (f[i][T] + f[i - 1][S]) % mod;
    }
    
    for(ri S = 0; S <= lim; S ++)
    if((S & gg) != gg) ans = (ans - f[N][S] + mod) % mod;
    printf("%d\n", ans);
    return 0;
}

 

T4

留坑...

咕咕咕咕咕咕咕...

posted @ 2018-08-22 21:06  remoon  阅读(286)  评论(0编辑  收藏  举报