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多线程中,队列和执行的排列组合结果分析
本文是对以往学习的多线程中知识点的一个整理. 多线程中的队列有:串行队列,并发队列,全局队列,主队列. 执行的方法有:同步执行和异步执行.那么两两一组合会有哪些注意事项呢? 如果不是在董铂然博客园看到 ...
随机推荐
- CLI-error
SQL_ERROR: One of the following occurred: RecNumber was negative or 0. BufferLength was less than ze ...
- Eclipse必须掌握的快捷键
Eclipse快捷键 Ctrl + / 添加//注释.删除//注释 Ctrl + 1 快速修复错误 Ctrl + Shift + f 格式化文档 Shift + Enter Shift + Ctrl ...
- C插入排序
#include "stdio.h" int main() { ,,,,,}; int i,j; ;j<]);j++) { int key = a[j]; ;i>=&a ...
- JQGrid+Nhibernate+Webservice+Linq
先上效果图: 前台代码(jqgridtest.aspx): <%@ Page Language="C#" AutoEventWireup="true" ...
- Repeater中将int类型和bool类型的字段以字符显示出来
图一 图二 比如将图一中是否显示中的列显示以图二中的方式显示: 方法1: 1.在后台编写方法:a.aspx.cs代码如下 //IsShow字段显示的方法public string GetStrIsSh ...
- DTCMS视频模版更改,
1.去掉style.css中视频的高度 .video-box{ position:relative; width:100%; height:473px; _clear:both; _display:i ...
- asp.net 时间比较,常用于在某段时间进行操作
DateTime.Compare(t1,t2)比较两个日期大小,排前面的小,排在后面的大,比如:2011-2-1就小于2012-3-2返回值小于零: t1 小于 t2. 返回值等于零 : t1 等于 ...
- JS中的!=、== 、!==、===的用法和区别。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 var num = 1; var str = '1'; var test = 1; t ...
- 解决Ajax跨域问题:Origin xx is not allowed by Access-Control-Allow-Origin.
一:使用jsonp格式, 如jquery中ajax请求参数 dataType:'JSONP'. <html> <head> <title>title</t ...
- laravel--模型中各种属性详解
首先以这个模型为例 首先看, 1.$guarded属性,$fillable属性 $guarded属性一般是和$fillable对应的,不是一起存在但是互相使用,他们都是laravel的批量赋值方法cr ...