codechef [snackdown2017 Onsite Final] AND Graph

传送门

题解给出了一个很强势的dp:

i<K

$$dp[i][len]*Fib[len+2-(t[i]==1)] -> dp[i+1][len]$$

$$dp[i][len]*Fib[len+1-(t[i]==1)] -> dp[i+1][len+1]$$

i>=K

$$dp[i][len]*Fib[len+2-(t[i]==1)-(s[i]==1)] -> dp[i+1][len]$$

其中K是s的前导0个数

意思是单独考虑每一位,相邻两个不能同时为1,方案数是斐波那契数,然后就直接搞了。

#include<cstdio>
#include<cstring>
#include<algorithm>
#define MN 5001
using namespace std;

const int MOD=998244353;
int T,n,dp[MN][MN],k,F[MN],MMH;
char s[MN],t[MN];
int main(){
    F[0]=0;F[1]=1;
    for (int i=2;i<=5000;i++) F[i]=F[i-1]+F[i-2],F[i]-=F[i]>=MOD?MOD:0;
    scanf("%d",&T);
    while (T--){
        scanf("%s%s",s,t);MMH=0;
        n=strlen(s);k=0;
        while (s[k]==‘0‘) k++;
        for (int i=0;i<n;i++)
        for (int j=0;j<=n;j++) dp[j][i]=0;
        dp[0][0]=1;
        for (int i=0;i<n;i++){
            for (int j=0;j<k;j++){
                dp[j+1][i]=(1LL*dp[j][i]*F[i+2-(t[j]==‘1‘)]+dp[j+1][i])%MOD;
                dp[j+1][i+1]=(1LL*dp[j][i]*F[i+1-(t[j]==‘1‘)]+dp[j+1][i+1])%MOD;
            }
            for (int j=k;j<n;j++) dp[j+1][i]=(1LL*dp[j][i]*F[i+2-(t[j]==‘1‘)-(s[j]==‘1‘)]+dp[j+1][i])%MOD;
            (MMH+=dp[n][i])%=MOD;
        }
        printf("%d\n",MMH);
    }
}

时间: 2024-08-25 18:34:37

codechef [snackdown2017 Onsite Final] AND Graph的相关文章

CodeChef Counting on a directed graph

Counting on a directed graph Problem Code: GRAPHCNT All submissions for this problem are available. Read problems statements in Mandarin Chineseand Russian. Given an directed graph with N nodes (numbered from 1 to N) and M edges, calculate the number

HDU 3296 &amp; POJ 3138 Acm Team Section(数学)

题目链接: HDU: http://acm.hdu.edu.cn/showproblem.php?pid=3296 POJ:  http://poj.org/problem?id=3138 Acm Team Section Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 159    Accepted Submission(s): 47

可视化工具solo show-----Prefuse自带例子GraphView讲解

2014.10.15日以来的一个月,挤破了头.跑断了腿.伤透了心.吃够了全国最大餐饮连锁店——沙县小吃.其中酸甜苦辣,绝不是三言两语能够说得清道的明的.校招的兄弟姐妹们,你们懂得…… 体会最深的一句话还是:出来混,迟早要还的. 一个月过去了,迷茫之际有太多无奈,无奈中又夹杂些许庆幸,岁月匆匆,人生不息,奋斗不止. 遵守最初的诺言,继续走我可视化的道路: 上集摘要:一个月博文中大概介绍了可视化的一些常用工具,从可操作性.实用性.交互性等各方面进行了简单的对比和总结,具体参见http://www.c

RelativeLayout源码解析

为什么学习 一直对RelativeLayout如何把xml中的属性转换成子view的真实坐标比较感兴趣,并且网上对RelativeLayout这部分资料比较少,希望将自己对RelativeLayout这部分源码理解写出来,跟大家分享一下. 什么是RelativeLayout 中文名叫相对布局,可以指定内部子view之间的相互关系,从而可以绘制出更精确的UI 但是相比于LinearLayout,RelativeLayout在measure的时候每次都一定会遍历2次,性能有所降低,在实际使用的时候,

Falcon Genome Assembly Tool Kit Manual

Falcon Falcon: a set of tools for fast aligning long reads for consensus and assembly The Falcon tool kit is a set of simple code collection which I use for studying efficient assembly algorithm for haploid and diploid genomes. It has some back-end c

[CodeChef - GERALD07 ] Chef and Graph Queries

Read problems statements in Mandarin Chineseand Russian. Problem Statement Chef has a undirected graph G. This graph consists of N vertices and M edges. Each vertex of the graph has an unique index from 1 to N, also each edge of the graph has an uniq

Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) G - Xor-matic Number of the Graph 线性基好题

G - Xor-matic Number of the Graph 上一道题的加强版本,对于每个联通块需要按位算贡献. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PII pair<int, int> #define PLI pair<LL, int> #define ull unsigned lo

【CodeChef】Chef and Graph Queries

Portal --> CC Chef and Graph Queries Solution 快乐数据结构题(然而好像有十分优秀的莫队+可撤销并查集搞法qwq) 首先考虑一种方式来方便一点地..计算一个图的联通块数量:我们可以考虑容斥,维护每个连通块的生成树,然后\(n-\)生成树边数就是答案了 这样有一个好,加边的时候比较好处理,但是光这样并不能解决我们的问题 ? 顺着这个思路思考,先不考虑时间复杂度,对于一个询问,考虑将编号为\(l\sim r\)的边一条一条加入第\(1\sim l-1\)条

[bzoj3514][CodeChef GERALD07] Chef ans Graph Queries [LCT+主席树]

题面 bzoj上的强制在线版本 思路 首先可以确定,这类联通块相关的询问问题,都可以$LCT$+可持久化记录解决 用LCT维护生成树作为算法基础 具体而言,从前往后按照边的编号顺序扫一遍边 如果这条边两端不在同一个$LCT$联通块中,则$link$ 否则$cut$掉当前连接两条边的路径上的编号最小的边,并$link$ 记录$ntr[i]$表示第$i$条边触发第二种情况时$link$前$cut$掉的边的编号 如果触发第一种情况,则$ntr[i]=0$ 如果为自环,则$ntr[i]=i$ 这样记录之