zoukankan      html  css  js  c++  java
  • 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:

     1 #include<string>
     2 #include<cstring>
     3 #include<stdio.h>
     4 #include<iostream>
     5 #include<string.h>
     6 using namespace std;
     7 int main()
     8 {
     9     long long m,n;
    10     char a[1000][1000];
    11     long long sum=1;
    12     cin>>n>>m;
    13     for (long long i=1;i<=n;i++)
    14         scanf("%s",a[i]);
    15     for (long long i=0;i<=m-1;i++)
    16     {
    17         long long cnt=0;
    18         long long b[30]={0};
    19         for (long long j=1;j<=n;j++)
    20             b[a[j][i]-'A']++;
    21         for (long long j=0;j<=29;j++)
    22             if (b[j]!=0) cnt++;
    23         sum*=cnt;
    24         sum=sum%1000000007;
    25     }
    26     cout<<sum<<endl;
    27     return 0;
    28 }
  • 相关阅读:
    JS实现——用3L和5L量出4L的水
    岭回归与Lasso回归
    简单多元线性回归(梯度下降算法与矩阵法)
    【TensorFlow】tf.nn.softmax_cross_entropy_with_logits的用法
    tensorflow sigmoid_cross_entropy_with_logits 函数解释
    tensorflow 线性回归解决 iris 2分类
    神经网络激活函数
    神经网络防止过拟合的方法
    网络流量分析——NPMD关注IT运维、识别宕机和运行不佳进行性能优化。智能化分析是关键-主动发现业务运行异常。科来做APT相关的安全分析
    cnn汉字识别 tensorflow demo
  • 原文地址:https://www.cnblogs.com/Enumz/p/3871701.html
Copyright © 2011-2022 走看看