zoukankan      html  css  js  c++  java
  • AGC027 E


    目录

    题目链接

    AGC027 E - ABBreviate

    题解

    神仙啊
    建议查看https://img.atcoder.jp/agc027/editorial.pdf
    定义a = 1,b = 1发现在%3的情况下所有变换的相等的
    性质:一个字符串,能变成字符c的条件是val[a] == val[c]并且a中有一个可以变换的位置
    只需要判断这种变换不经过ababab这种就好了
    那我们要求得就把字符串划分为k段,第i段的val值和第i字符的val值相等
    f_i表示前i个看做一段的方案数

    代码

    
    #include<cstdio> 
    #include<cctype> 
    #include<cstring> 
    #include<algorithm> 
    #define gc getchar() 
    #define pc putchar
    #define LL long long
    inline int read() { 
    	int x = 0,f = 1; 
    	char c = getchar(); 
    	while(c < '0' || c > '9') c = gc; 
    	while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar(); 
    	return x * f; 
    }
    void print(LL x) { 
    	if(x < 0) { 
    		pc('-'); 
    		x = -x; 
    	} 
    	if(x >= 10) print(x / 10); 
    	pc(x % 10 + '0'); 
    } 
    const int maxn = 100007; 
    char t[maxn]; 
    int n,s[maxn]; 
    int f[maxn]; 
    const int mod = 1e9 + 7; 
    int main() { 
    	scanf("%s",t + 1); 
    	n = strlen(t + 1); 
    	bool flag = false ; 
    	for(int i = 2;i <= n;++ i) if(t[i] == t[i - 1])flag = true; 
    	if(!flag) { 
    		puts("1");  
    		return 0; 
    	} 
    	int now = 0,pre[3] = {0,-1,-1}; 
    	f[0] = 1; 
    	for(int i = 1;i <= n;++ i) { 
    		now = (now + 2 - (t[i] == 'a')) % 3; 
    		if(!now && i < n) f[i] = 1; 
    		++ now,now %= 3; 
    		if(pre[now] != - 1) (f[i] += f[pre[now]]) %= mod;  
    		++ now,now %= 3; 
    		if(pre[now] != -1) (f[i] += f[pre[now]]) %= mod;
    		++ now,now %= 3; 
    		pre[now] = i; 
    	} 
    	print(f[n]); 
    } 
    
  • 相关阅读:
    论JS函数传参时:值传递与引用传递的区别
    关于 rem
    致——自己
    用CSS3写的钟表
    HTML标签marquee实现滚动效果
    手机号截取
    CSS3绘制环形进度条
    限制内容长度(CSS,jQuery)
    移动web开发中遇到的一些问题收纳
    移动平台中 meta 标签的使用
  • 原文地址:https://www.cnblogs.com/sssy/p/9709739.html
Copyright © 2011-2022 走看看