• CF152C Pocket Book


    题面翻译

    给出 n 个长度为 m 的字符串,定义一次操作(i , j , k)表示可以按任意选取1 <= i < j <= n ,1 <= k <= m ,使得编号为 i , j的两个字符串的长度为 k 的前缀互换;问任意多次操作后能得到的不同字符串的最大数量。
    你可以将这 n 个字符串看为一个集合,然后将每一次操作后新产生的字符串加入到这个集合中,众所周知集合是满足互异性的,即集合内的字符串不能有相同。答案相当于经过任意多次操作后,集合所包含的最多的元素个数是多少

    题目描述

    One day little Vasya found mom’s pocket book. The book had $ n $ names of her friends and unusually enough, each name was exactly $ m $ letters long. Let’s number the names from $ 1 $ to $ n $ in the order in which they are written.

    As mom wasn’t home, Vasya decided to play with names: he chose three integers $ i $ , $ j $ , $ k $ ( $ 1<=i

    You wonder how many different names Vasya can write instead of name number $ 1 $ , if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers $ i $ , $ j $ , $ k $ independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo $ 1000000007 $ $ (10^{9}+7) $ .

    输入格式

    The first input line contains two integers $ n $ and $ m $ ( $ 1<=n,m<=100 $ ) — the number of names and the length of each name, correspondingly. Then $ n $ lines contain names, each name consists of exactly $ m $ uppercase Latin letters.

    输出格式

    Print the single number — the number of different names that could end up in position number $ 1 $ in the pocket book after the applying the procedures described above. Print the number modulo $ 1000000007 $ $ (10^{9}+7) $ .

    样例 #1

    样例输入 #1

    2 3
    AAB
    BAA
    
    • 1
    • 2
    • 3

    样例输出 #1

    4
    
    • 1

    样例 #2

    样例输入 #2

    4 5
    ABABA
    BCGDG
    AAAAA
    YABSA
    
    • 1
    • 2
    • 3
    • 4
    • 5

    样例输出 #2

    216
    
    • 1

    提示

    In the first sample Vasya can get the following names in the position number $ 1 $ : “AAB”, “AAA”, “BAA” and “BAB”.

    分析

    我们看看样例:

    AAB
    BAA
    
    • 1
    • 2

    在这个数据中,每个字符串的各位不相等的数量分别为:2,1,2(AB,A,BA)。

    根据组合数中的乘法原理: N = m 1 ∗ m 2 ∗ . . . ∗ m n N = m 1 ∗ m 2 ∗ . . . ∗ m n N=m1∗m2∗...∗mnN=m_1*m_2*...*m_n N=m1m2...mnN=m1m2...mn​。所以我们只需找出每个字符串中各位不相等的数量,再将其相乘即可。

    代码

    #include
    
    #define int long long//以防万一 
    
    const long long p=1000000007;//题目要求取模 
    
    using namespace std;
    
    int m,n;
    
    string s[100000];//输入的字符串 
    
    int ans=1;//总方案数 
    
    bool bo[100000];//用来判断该字母是否重复 
    
    int k;
    
    signed main()
    {
    	cin>>n>>m;//输入字符串个数,输入每个字符串位数 
    	
    	for(int i=1;i<=n;i++)//输入n个字符串 
    	{
    		cin>>s[i];
    	}
    	
    	for(int i=0;i<m;i++)//枚举每一位 
    	{
    		memset(bo,0,sizeof(bo));//清空 
    		
    		k=0;//k表示不同的字符的个数 
    		
    		for(int j=1;j<=n;j++)//枚举在这一位的每一行行 
    		{
    			if(bo[s[j][i]-65]==0)//这个字符还没有重复 
    			{
    				bo[s[j][i]-65]=1;//标记 
    				
    				k++;//不重复数量+1 
    			}
    		}
    
    		ans=ans*k;//根据乘法原理求总方案数
    		
    		ans=ans%p; //取模 
    	}
    	
    	cout<<ans;//输出总方案数 
    	
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
  • 相关阅读:
    自定义弹窗(含生成zxing二维码功能)看这一篇就够了
    java开发手册-04安全规约
    免费域名证书最新申请方式大全
    谷粒商城十二性能压测
    vue3学习源码笔记(小白入门系列)------ 重点!响应式原理 代码逐行分析
    canvas 学习
    聊聊ip与mac地址之间那些事
    畜牧猪舍养殖成功 管理效率提高的背后原因
    Vue3 快速上手从0到1,两小时学会【附源码】
    UDP和TCP的区别
  • 原文地址:https://blog.csdn.net/m0_66603329/article/details/126857477