AGC022E - Median Replace

题面描述

Solution

直接构造自动机,模拟每次在末尾加一个字符的当前状态的方案数f[state]f[state]f[state],状态很少,直接打表转移即可。

时间复杂度O(n)O(n)O(n)。

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se secondusing namespace std;template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=1e9+7;
const int MAXN=600005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{int f=1,x=0; char c=getchar();while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }return x*f;
}
char st[MAXN];
int f[MAXN][8];
int to[8][2]={{2,1},{4,3},{6,5},{3,3},{7,1},{2,1},{2,2},{4,4}};
int upd(int x,int y){ return x+y>=mods?x+y-mods:x+y; }
int main()
{scanf("%s",st);int len=strlen(st);f[0][0]=1;for (int i=0;i<len;i++)for (int j=0;j<=7;j++) {if (st[i]!='0') f[i+1][to[j][1]]=upd(f[i+1][to[j][1]],f[i][j]);if (st[i]!='1') f[i+1][to[j][0]]=upd(f[i+1][to[j][0]],f[i][j]);}printf("%d\n",upd(f[len][1],f[len][3]));return 0;
}

AGC022E - Median Replace相关推荐

  1. AtCoder AGC022E Median Replace (字符串、自动机、贪心、计数)

    题目链接 https://atcoder.jp/contests/agc022/tasks/agc022_e 题解 感觉官方题解很神仙,听完另一种做法之后发现是自己太智障了 考虑一个串怎么样可以缩成 ...

  2. AtCoder3950 [AGC022E] Median Replace(DFA + dp)

    problem solution 可以从 DFA\text{DFA}DFA 的思想来考虑这道题. 考虑建一个 DFA\text{DFA}DFA 只接受最后可以变成字符串 111 的原串. 因为每次是选 ...

  3. AT3950-[AGC022E]Median Replace【贪心,dp】

    正题 题目链接:https://www.luogu.com.cn/problem/AT3950 题目大意 一个包含?,0,1?,0,1?,0,1的长度为奇数的序列,把???替换为0/10/10/1.每 ...

  4. [总结]2019年10月 OI学习/刷题记录

    10月份记录! 2019/10/1 UOJ #74. [UR #6]破解密码 Hash+分类讨论 UOJ #75. [UR #6]智商锁 Matrix-Tree定理+随机化 UOJ #76. [UR ...

  5. 2020.5月做题记录

    2020.5.3 NOI2016 优秀的拆分 [链接] 想写SAM结果自闭了. BZOJ3064 CPU监控 线段树历史最大值模板题. 注意到其实带维护历史最大值最大的问题时维护tag. 这里我们将t ...

  6. python中的scaler_Python preprocessing.MaxAbsScaler方法代码示例

    本文整理汇总了Python中sklearn.preprocessing.MaxAbsScaler方法的典型用法代码示例.如果您正苦于以下问题:Python preprocessing.MaxAbsSc ...

  7. azure机器学习_Azure机器学习中的数据清理

    azure机器学习 介绍 (Introduction) After discussing the basic features of Azure Machine Learning in my prev ...

  8. DataCamp中Introduction to Python之NumPy

    这一节开始练习numpy Your First NumPy Array In this chapter, we're going to dive into the world of baseball. ...

  9. 【CodeForces - 1201C】Maximum Median(思维,水题)

    题干: You are given an array aa of nn integers, where nn is odd. You can make the following operation ...

最新文章

  1. 常见蓝牙模块介绍和AT指令
  2. NOIP2016 D2T3 愤怒的小鸟
  3. kindEditor富文本编辑器的工具栏设置
  4. relation does not exist报错是什么意思_为什么Zookeeper天生就是一副分布式锁的胚子?...
  5. “老师,我写着写着就 强制交卷了……”
  6. Centos 7和 Centos 6开放查看端口 防火墙关闭打开
  7. java闰年的年份,Java案例-判断给定年份是闰年
  8. 怎样用VB获得Windows各类系统目录
  9. java 圆弧,JavaFX圆弧
  10. SystemMenu添加Item
  11. 【带权并查集详解】以HDU 3038为例【How Many Answers Are Wrong】
  12. sqlplus / as sysdba ORA-01017
  13. 网络安全之DOS攻击
  14. python3 scrapy中文文档_Python3爬虫入门:Scrapy 框架
  15. Vista Ultimate X64 绝对正宗的激活工具
  16. 成立一年,手游交叉推广交易社区Chartboost已有8000款游戏加入
  17. 外星文明 未来计算机,科学家有望未来在地球“设计打印”外星生命
  18. SQL注入-04-(最后有实战教学)关系注入逻辑注入
  19. VMware虚拟机文件后缀详解
  20. 获取当天日期的前一天或前几天,查询一天内的数据

热门文章

  1. 奇妙的数学动图,美到令人窒息!
  2. 微型计算机名词术语,微型计算机及接口技名词解释题及解答题.doc
  3. ffbe攻略站_最终幻想勇气启示录ffbe兵员强化攻略
  4. promtail 配置详解_基于loki+promtail+grafana技术的日志集合
  5. unity 坐标系转换_Unity的几种坐标系及相互转换
  6. io python 读取pdf_Python读取PDF文件--pdfminer
  7. 服务器运维监控指标,运维体系~指标监控~Prometheus监控告警与日志
  8. c语言的使用比例远远高于python语言对吗_Python和C语言的语法有什么不同?
  9. 存储过程mysql报错1271_mysqldump备份失败以及解决方法汇总
  10. python中valueerror怎么改_如何修复Python ValueError:错误的元数据?