首页 > 其他分享 >ABC246F typewriter 题解

ABC246F typewriter 题解

时间:2022-10-24 08:23:56浏览次数:75  
标签:return int 题解 ret getchar ABC246F 字符串 define typewriter

ABC246F typewriter Solution

目录

更好的阅读体验戳此进入

题面

给定 $ n $ 个字符串,字符集为小写字母,可以任意选择一个字符串,作为字符库,然后(可多次选择同一字符)任意组成长度为 $ l $ 的字符串,求一共能形成多少种长度为 $ l $ 的字符串。

Solution

容斥较为显然,显然最终答案也就是,用任意一个字符集形成的字符串减去任意两个的加上任意三个...于是我们考虑令全集为 $ S = 2^n - 1 $ 然后对其进行枚举子集,二进制第 $ i $ 位为 $ 1 $ 或 $ 0 $ 代表是否考虑这个数,所以枚举的时候直接 __builtin_popcount() 算一下个数,奇数代表加,反之减。然后对于每一个字符串,因为字符集较小,也用一个 int 的二进制表示是否存在对应的字符,然后把需要的字符串都与起来,设数量为 $ \xi $,则此次运算的字符集大小则为 $ \xi $,所以此次答案为 $ \xi^l $,加减考虑好即可。

Code

#define _USE_MATH_DEFINES
#include <bits/extc++.h>

#define PI M_PI
#define E M_E
#define npt nullptr
#define SON i->to
#define OPNEW void* operator new(size_t)
#define ROPNEW(arr) void* Edge::operator new(size_t){static Edge* P = arr; return P++;}

using namespace std;
using namespace __gnu_pbds;

mt19937 rnd(random_device{}());
int rndd(int l, int r){return rnd() % (r - l + 1) + l;}
bool rnddd(int x){return rndd(1, 100) <= x;}

typedef unsigned int uint;
typedef unsigned long long unll;
typedef long long ll;
typedef long double ld;

#define MOD 998244353

template<typename T = int>
inline T read(void);

int N, L;
int str[20];
int readStr(void){
    int ret(0);
    char c = getchar();
    while(!islower(c))c = getchar();
    vector < int > val;
    while(islower(c)){
        ret |= 1 << (c - 'a');
        c = getchar();
    }return ret;
}
ll qpow(ll a, ll b){
    ll ret(1), mul(a);
    while(b){
        if(b & 1)ret = ret * mul % MOD;
        b >>= 1;
        mul = mul * mul % MOD;
    }return ret;
}

int main(){
    N = read(), L = read();
    ll ans(0);
    for(int i = 1; i <= N; ++i)str[i] = readStr();
    // for(int i = 1; i <= N; ++i)
    //     cout << bitset < 32 > (str[i]) << endl;
    int Smx = (1 << N) - 1;
    // cout << "Smx" << bitset < 32 > (Smx) << endl;
    for(int S = Smx; S; S = (S - 1) & Smx){
        // cout << "S:" << bitset < 32 > (S) << endl;
        int cnt = __builtin_popcount(S);
        int tot((1 << 26) - 1);
        for(int i = 0; i <= N - 1; ++i)
            if((1 << i) & S)tot &= str[i + 1];
        // cout << "tot:" << bitset < 32 > (tot) << endl;
        ans = (ans + qpow(__builtin_popcount(tot), L) * ((cnt & 1) ? 1 : -1) + MOD) % MOD;
    }
    printf("%lld\n", ans);
    fprintf(stderr, "Time: %.6lf\n", (double)clock() / CLOCKS_PER_SEC);
    return 0;
}

template<typename T>
inline T read(void){
    T ret(0);
    short flag(1);
    char c = getchar();
    while(c != '-' && !isdigit(c))c = getchar();
    if(c == '-')flag = -1, c = getchar();
    while(isdigit(c)){
        ret *= 10;
        ret += int(c - '0');
        c = getchar();
    }
    ret *= flag;
    return ret;
}

UPD

update-2022_10_21 初稿

标签:return,int,题解,ret,getchar,ABC246F,字符串,define,typewriter
From: https://www.cnblogs.com/tsawke/p/16820300.html

相关文章

  • ABC246D 2-variable Function 题解
    ABC246D2-variableFunctionSolution目录ABC246D2-variableFunctionSolution更好的阅读体验戳此进入题面SolutionCodeUPD更好的阅读体验戳此进入题面存在函数$f......
  • ABC246E Bishop 2 题解
    ABC246EBishop2Solution目录ABC246EBishop2Solution更好的阅读体验戳此进入题面SolutionCodeUPD更好的阅读体验戳此进入题面给定有障碍的网格图,.为空地,#为障碍......
  • LG-P5104 红包发红包 题解
    LG-P5104红包发红包Solution目录LG-P5104红包发红包Solution更好的阅读体验戳此进入UPD更好的阅读体验戳此进入(建议您从上方链接进入我的个人网站查看此Blog,在Luo......
  • ABC246C Coupon 题解
    ABC246CCouponSolution目录ABC246CCouponSolution更好的阅读体验戳此进入题面SolutionCodeUPD更好的阅读体验戳此进入题面$n$个物品第$i$个价格为$a_i$,......
  • The 18th Zhejiang Provincial Collegiate Programming Contest题解
    A.LeagueofLegends水题。点击查看代码#include<bits/stdc++.h>usingnamespacestd;#defineintlonglonginta[6];intb[6];signedmain(){for(......
  • ABC274 题解
    A题目:给定\(A,B\)输出\({B}\over{A}\)保留\(3\)位小数。简答题,和A+Bproblem一样,除一除,保留一下小数。B题目:给定一个\(n\)行\(m\)列由'.'和'#'的方阵,求每列......
  • 【题解】The 2021 ICPC Asia Macau Regional Contest - E Pass The Ball
    问题描述解释相当于给定一个置换群,求\(\sum\limits_{i=1}^{n}i*b_{i}\)题目分析本题这种传球的关系显然是存在循环节的,先考虑一个大小为\(m\)的环,显然我们可以用......
  • 0025:2011年NOIp普及组真题——瑞士轮题解
    题目链接:https://www.luogu.com.cn/problem/P1309如果是新手可能马上会想到sort排序,每比一次就排一次,但是这样的时间复杂度有点高,只有60分;这是因为每次比完赛会产生两个......
  • ABC274D题解
    这是一道较为简单的可行性DP。首先看到题目,很容易想到将横纵坐标一起进行处理,但显然时间会炸飞。所以我们将横纵坐标拆开分别处理,那么就有如下状态:\(dpa_{i,j}\)表示在......
  • Ubuntu20.04运行wiki.js服务器出错问题解决方法
    错误代码:root@xxx:/home/xxxxx/wiki#nodeserverLoadingconfigurationfrom/home/xxxxx/wiki/config.yml...OK2022-10-23T05:00:25.563Z[MASTER]info:============......