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]); 
    } 
    
  • 相关阅读:
    SQL JOIN
    string.Empty, "" 和 null 三者的区别
    java JDBC
    java 自定义注解
    Spring Bean自动检测
    Spring Aware接口
    IObservable 接口
    CloseHandle()函数的使用
    [置顶] 记一次讲座与前辈的对话
    让用户关上门说话:覆盖全美6000个社区的邻居私密社交网站Nextdoor是如何壮大的?
  • 原文地址:https://www.cnblogs.com/sssy/p/9709739.html
Copyright © 2011-2022 走看看