首页 > 其他分享 >NOIP 2021

NOIP 2021

时间:2022-09-20 20:35:13浏览次数:41  
标签:fop NOIP int read 2021 ans include mod

报数 (黄)

小清新筛子签到题

点击查看代码
#include <cstdio> 
#include <cstring> 
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#define ff fflush(stdout)
using namespace std;

typedef long long ll;

int read() {
    int x = 0;
    char c;
    bool f = 0;
    while (!isdigit(c = getchar())) {
        if (c == '-') f = 1;
    }
    do {
        x = (x << 1) + (x << 3) + (c ^ 48); 
    } while (isdigit(c = getchar()));
    if (f) return -x;
    return x;
}

const int maxn = 1e7 + 3, mod = 1e9 + 7;

bool vis[maxn];
int ans[maxn];

void Euler(int x) { for (int i = x; i < maxn; i += x) vis[i] = 1; }
bool Check(int x) {
    while (x) {
        if (x % 10 == 7) return 1;
        x /= 10;
    }
    return 0;
}

int main() {
    for (int i = 1; i < maxn; ++i) if (Check(i)) Euler(i);
    int lst = 0;
    for (int i = 1; i < maxn; ++i) {
        if (vis[i]) ans[i] = -1;
        else ans[lst] = i, lst = i; 
    }
    int T = read();
    while (T--) printf("%d\n", ans[read()]);
}

数列 (蓝)

终于不鸽了)

看到数据范围果断乱搞高维 DP

设 \(f[i][j][k][l]\) 表示考虑到数列 \(a\) 中值小于等于 \(i\) 的项,其中有 \(j\) 个值没有确定,\(S\) 的二进制从 \(2 ^ i\) 对应的这一位开始的状态(状压),前面的二进制位有 \(l\) 个 1

这状态出来转移就好搞了

\(f[i + 1][j - u][(k >> 1) + u][l + (k \,\&\, 1)]+=f[i][j][k][u] * C_j^u * v_{i+1}^u\)

试了试用宏写 for 循环,发现非常好用)

点击查看代码
#include <bits/stdc++.h>
#define ff fflush(stdout)
#define fop(x, l, r) for (int x = l; x <= r; ++x)
#define fio(x, r, l) for (int x = r; x >= l; --x)
using namespace std;

typedef long long ll;

int read() {
    int x = 0;
    char c;
    bool f = 0;
    while (!isdigit(c = getchar())) {
        if (c == '-') f = 1;
    }
    do {
        x = (x << 1) + (x << 3) + (c ^ 48); 
    } while (isdigit(c = getchar()));
    if (f) return -x;
    return x;
}

const int maxn = 31, maxm = 101, mod = 998244353;

void Add(int &x, int y) {
    x += y;
    if (x >= mod) x -= mod;
}

int Pow(ll a, int b) {
    ll ans = 1;
    while (b) {
        if (b & 1) ans = ans * a % mod;
        a = a * a % mod, b >>= 1;
    }
    return ans;
}

int f[maxm][maxn][maxn][maxm];
int v[maxm];
int c[maxn][maxn];

int main() {
    int n = read(), m = read(), ik = read();
    fop(i, 0, m) v[i] = read();
    fop(i, 0, maxn - 1) {
        c[i][0] = c[i][i] = 1;
        fop(j, 1, i - 1) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
    }
    fop(i, 0, n) f[0][i][n - i][0] = 1ll * c[n][i] * Pow(v[0], n - i) % mod;
    fop(i, 0, m - 1) fop(j, 0, n) fop(k, 0, n) fop(l, 0, ik) fop(u, 0, j) {
        Add(f[i + 1][j - u][(k >> 1) + u][l + (k & 1)], 1ll * f[i][j][k][l] * c[j][u] % mod * Pow(v[i + 1], u) % mod);
    }
    int ans = 0;
    fop(k, 0, n) fop(l, 0, ik) {
        if (__builtin_popcount(k) + l <= ik) Add(ans, f[m][0][k][l]); 
    }
    printf("%d\n", ans);
}

标签:fop,NOIP,int,read,2021,ans,include,mod
From: https://www.cnblogs.com/eafoo/p/16703598.html

相关文章

  • 2022-2023学年 20211319蓝宇 《信息安全专业导论》第四周学习总结
    作业信息|2020-2021-1信息安全专业导论|https://edu.cnblogs.com/campus/besti/2020-2021-1fois|2020-2021-1信息安全专业导论第三周作业|第三周作业(必学,选做)-作业-2......
  • 做题记录整理dp1 P1541. [NOIP2010 提高组] 乌龟棋(2022/9/20)
    P1541.[NOIP2010提高组]乌龟棋把每个牌选多少个塞进dp的四个维度里,就可以做到无后效性了#include<bits/stdc++.h>usingnamespacestd;#definefor1(i,a,b)for(ll......
  • CSPS2021回文
    [CSP-S2021]回文题目描述给定正整数\(n\)和整数序列\(a_1,a_2,\ldots,a_{2n}\),在这\(2n\)个数中,\(1,2,\ldots,n\)分别各出现恰好\(2\)次。现在进行\(......
  • NOI与NOIP的区别
    NOI:全国青少年信息学奥林匹克(NOI)是国内包括港澳在内的省级代表队最高水平的大赛,自1984年至今,在国内包括香港、澳门组织竞赛活动。每年经各省选拔产生5名选手(其中一名是女选......
  • [训练记录]2021icpc上海
    D.StrangeFractions$\frac{a}{b}=x$原式即$x+\frac{1}{x}=\frac{p}{q}$解方程然后$\delta$为整数即可算出对应的$a$和$b$#include<bits/stdc++.h>usingname......
  • SWERC 2021-2022 部分简要题解
    比赛链接:https://codeforc.es/contest/1662。前言「部分」「简要」题解。A-OrganizingSWERC直接判断。C-EuropeanTrip如果不考虑限制,我们可以直接矩乘。考虑......
  • 4. [2003年NOIP普及组] 栈
    #include<iostream>#include<cstdio>#include<cmath>usingnamespacestd;//因为我们要求的方案数,可以借用离散的思想——//不用考虑每个数组中具体是那个数//只......
  • CSP2021-s题解
    T1廊桥分配题目链接P7913[CSP-S2021]廊桥分配\(Lemma:\)对于已经存在的廊桥集合,加入新的廊桥不会影响之前分配好的航班。证明:由于题目所给限制,若有空廊桥,则航......
  • 上市公司环保投入、环保支出、环保投资数据(1990-2021)
    上市公司环保投入数据、上市公司环保支出数据、上市公司环保投资数据(1990-2021)上市公司环保投入数据、上市公司环保支出数据、上市公司环保投资数据(1990-2021)上市公司环......
  • 2021年3月-第02阶段-前端基础-移动WEB开发-移动WEB开发之_响应式布局
    移动端WEB开发之响应式布局1.0响应式开发原理1.1响应式开发原理就是使用媒体查询针对不同宽度的设备进行布局和样式的设置,从而适配不同设备的目的。设备的划分情况:......