CodeForces152C——Pocket Book(排列组合问题)
Pocket Book
Description
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 < j ≤ n, 1 ≤ k ≤ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".
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 (109 + 7).
Input
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.
Output
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 (109 + 7).
Sample Input
Input
2 3
AAB
BAA
Output
4
Input
4 5
ABABA
BCGDG
AAAAA
YABSA
Output
216
Hint
In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
题目大意:
Vasya很调皮,他进行了某个恶作剧。。
恶作剧:有N本书,把第i本书和第j本书的书名的前k个字符互换。(这N本书的名字长度相同)
输出有多少种书名组合。PS:输出=答案%(10^9+7)
结题思路:
简单的可能性计算。设X1为每本书的第一个字符的种类(例如样例2 有A B Y三种,X1==3),X2为每本书的第二个字节的种类,XN为每本书的第N个字符的种类。
答案=X1*X2*X3*。。。*XN
Code:
#include<string>
#include<cstring>
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
long long m,n;
char a[][];
long long sum=;
cin>>n>>m;
for (long long i=;i<=n;i++)
scanf("%s",a[i]);
for (long long i=;i<=m-;i++)
{
long long cnt=;
long long b[]={};
for (long long j=;j<=n;j++)
b[a[j][i]-'A']++;
for (long long j=;j<=;j++)
if (b[j]!=) cnt++;
sum*=cnt;
sum=sum%;
}
cout<<sum<<endl;
return ;
}
CodeForces152C——Pocket Book(排列组合问题)的更多相关文章
- 学习sql中的排列组合,在园子里搜着看于是。。。
学习sql中的排列组合,在园子里搜着看,看到篇文章,于是自己(新手)用了最最原始的sql去写出来: --需求----B, C, F, M and S住在一座房子的不同楼层.--B 不住顶层.C 不住底 ...
- .NET平台开源项目速览(11)KwCombinatorics排列组合使用案例(1)
今年上半年,我在KwCombinatorics系列文章中,重点介绍了KwCombinatorics组件的使用情况,其实这个组件我5年前就开始用了,非常方便,麻雀虽小五脏俱全.所以一直非常喜欢,才写了几 ...
- 【原创】开源.NET排列组合组件KwCombinatorics使用(三)——笛卡尔积组合
本博客所有文章分类的总目录:本博客博文总目录-实时更新 本博客其他.NET开源项目文章目录:[目录]本博客其他.NET开源项目文章目录 KwCombinatorics组件文章目录: 1. ...
- 【原创】开源.NET排列组合组件KwCombinatorics使用(二)——排列生成
本博客所有文章分类的总目录:本博客博文总目录-实时更新 本博客其他.NET开源项目文章目录:[目录]本博客其他.NET开源项目文章目录 KwCombinatorics组件文章目录: 1. ...
- 【原创】开源.NET排列组合组件KwCombinatorics使用(一)—组合生成
本博客所有文章分类的总目录:本博客博文总目录-实时更新 本博客其他.NET开源项目文章目录:[目录]本博客其他.NET开源项目文章目录 KwCombinatorics组件文章目录: 1. ...
- hdu1521 排列组合(指数型母函数)
题意: 有n种物品,并且知道每种物品的数量ki.要求从中选出m件物品的排数. (全题文末) 知识点: 普通母函数 指数型母函数:(用来求解多重集的排列问题) n个元素,其中a1,a2, ...
- [leetcode] 题型整理之排列组合
一般用dfs来做 最简单的一种: 17. Letter Combinations of a Phone Number Given a digit string, return all possible ...
- 排列组合算法(PHP)
用php实现的排列组合算法.使用递归算法,效率低,胜在简单易懂.可对付元素不多的情况. //从$input数组中取$m个数的组合算法 function comb($input, $m) { if($m ...
- iOS多线程中,队列和执行的排列组合结果分析
本文是对以往学习的多线程中知识点的一个整理. 多线程中的队列有:串行队列,并发队列,全局队列,主队列. 执行的方法有:同步执行和异步执行.那么两两一组合会有哪些注意事项呢? 如果不是在董铂然博客园看到 ...
随机推荐
- Shared library can't open object
将cpp的源文件和.so (shared object)链接成可执行程序之后,无法运行,提示如标题,实际就是找不到共享库. 最终找到了解决办法是: export LD_LIBRARY=./:$LD_L ...
- js 闭包 详解
闭包(closure)是Javascript语言的一个难点,也是它的特色,很多高级应用都要依靠闭包实现. 闭包的特性 闭包有三个特性: 1.函数嵌套函数 2.函数内部可以引用外部的参数和变量 3.参数 ...
- python的浅拷贝和深拷贝
python对象有两种拷贝的形式:浅拷贝和深拷贝. 在<python核心编程>中看到对这两种拷贝的分析,觉得十分收益,所以记录在此. id()方法:id()方法可以查看某个对象的ID,类似 ...
- C++ 关联容器详解——从内部结构到应用
关联容器不同于顺序容器的是:顺序容器底层用数组实现,为线性结构:关联容器在实现中,用到的非线性存储方式: 顺序容器是通过元素在容器中的位置顺序存储和访问元素,而关联容器是通过键(key)存储和读取元素 ...
- table如何在过宽的时候添加滚动条
在页面中,往往由于一个table的列过于多,导致页面放不下,然后内容各种挤变形. 这里说一个解决方法,.先用一个DIV把TABLE包围起来.然后给这个DIV设置宽度,并且设置overflow:auto ...
- Android “NetworkOnMainThreadException”出错原因及解决办法
原因: 不允许在主线程中通讯 方法1:非要在主线程中,当然也可以,这样去处理: StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Build ...
- Linux中Kill进程的N种方法
常规篇: 首先,用ps查看进程,方法如下: $ ps -ef …… smx 1822 1 0 11:38 ? 00:00:49 gnome-terminal smx ...
- Eclipse 中隐藏的 5 个非常有用的功能
Eclipse就是一头野兽.它也是一套设备,神秘但更具威力.有些人称它为一个持续变形机.另一些人则称它是一个变异体.不错,它很庞大,需要花费多年才能掌握.而在你好不容易掌握之后,你的老板出现了然后告诉 ...
- jsf2入门视频 教程
jsf2.0 入门视频 教程 需要的看下.初次录视频.还有很多需要完善. JSF交流QQ群84376982 JSF入门视频下载地址 http://pan.baidu.com/s/1jG3y4T4 ...
- c#3位一分(money)
NumberFormatInfo num = new NumberFormatInfo(); num.NumberDecimalDigits = 2; string ...