zoukankan      html  css  js  c++  java
  • BZOJ 2751: [HAOI2012]容易题(easy)

    题目

    2751: [HAOI2012]容易题(easy)

    Time Limit: 10 Sec  Memory Limit: 128 MB
    Submit: 906  Solved: 390
    [Submit][Status]

    Description


    为了使得大家高兴,小Q特意出个自认为的简单题(easy)来满足大家,这道简单题是描述如下:
    有一个数列A已知对于所有的A[i]都是1~n的自然数,并且知道对于一些A[i]不能取哪些值,我们定义一个数列的积为该数列所有元素的乘积,要求你求出所有可能的数列的积的和 mod 1000000007的值,是不是很简单呢?呵呵!

    Input


    第一行三个整数n,m,k分别表示数列元素的取值范围,数列元素个数,以及已知的限制条数。
    接下来k行,每行两个正整数x,y表示A[x]的值不能是y。

    Output

    一行一个整数表示所有可能的数列的积的和对1000000007取模后的结果。如果一个合法的数列都没有,答案输出0。

    Sample Input

    3 4 5
    1 1
    1 1
    2 2
    2 3
    4 3

    Sample Output

    90
    样例解释
    A[1]不能取1
    A[2]不能去2、3
    A[4]不能取3
    所以可能的数列有以下12种
    数列 积
    2 1 1 1 2
    2 1 1 2 4
    2 1 2 1 4
    2 1 2 2 8
    2 1 3 1 6
    2 1 3 2 12
    3 1 1 1 3
    3 1 1 2 6
    3 1 2 1 6
    3 1 2 2 12
    3 1 3 1 9
    3 1 3 2 18

    HINT

    数据范围

    30%的数据n<=4,m<=10,k<=10

    另有20%的数据k=0

    70%的数据n<=1000,m<=1000,k<=1000

    100%的数据 n<=109,m<=109,k<=105,1<=y<=n,1<=x<=m

    题解

    这道题很容易就能发现答案是每一位的可能取值的和的乘积,然后看着题的k很小,所以被修改的数也很小,所以大部分的和是相同的,我们就可以用快速幂了!欸,我只想说STL大法好!虽然会慢一些QAQ

    代码

     1 /*Author:WNJXYK*/
     2 #include<cstdio>
     3 #include<set>
     4 #include<map>
     5 #include<iostream>
     6 using namespace std;
     7 
     8 const int M=1000000007;
     9 
    10 map<int,int> minu;
    11 map<int,int>::iterator it;
    12 set<string> hash;
    13 
    14 long long Sum=0;
    15 int n,m,k;
    16 long long Ans=1;
    17 
    18 inline long long getTimes(long long n,int k){
    19     long long tmp=n;n=1;
    20     while(k){
    21         if (k&1) n=n*tmp%M;
    22         k/=2;
    23         tmp=tmp*tmp%M;
    24     } 
    25     return n;
    26 }
    27 
    28 inline string i2s(int x){
    29     string str;
    30     while(x){
    31         str=str+(char)(x%10+'0');
    32         x/=10;
    33     }
    34     return str;
    35 }
    36 
    37 int main(){
    38     scanf("%d%d%d",&n,&m,&k);
    39     Sum=((long long)n*((long long)n+(long long)1)/(long long)2)%M;
    40     for (int i=1;i<=k;i++){
    41         int x,y;
    42         scanf("%d%d",&x,&y);
    43         if (hash.insert(i2s(x)+"-"+i2s(y)).second==false) continue;
    44         it=minu.find(x);
    45         if (it==minu.end()){
    46             minu[x]=y%M;
    47         }else{
    48             minu[x]=(minu[x]+y)%M;
    49         }
    50     }
    51     for (it=minu.begin();it!=minu.end();it++){
    52         if ((*it).second%M<=Sum)
    53             Ans=Ans*(Sum-(*it).second%M)%M;
    54         else
    55             Ans=Ans*(Sum-(*it).second%M+M)%M;
    56     }
    57     Ans=Ans*getTimes(Sum,m-minu.size())%M;
    58     
    59     printf("%lld
    ",Ans);
    60     return 0;
    61 }
    View Code
  • 相关阅读:
    MOSS中的User的Title, LoginName, DisplayName, SID之间的关系
    如何在Network Monitor中高亮间隔时间过长的帧?
    SharePoint服务器如果需要安装杀毒软件, 需要注意什么?
    如何查看SQL Profiler? 如何查看SQL死锁?
    什么是Telnet
    The name or security ID (SID) of the domain specified is inconsistent with the trust information for that domain.
    Windows SharePoint Service 3.0的某个Web Application无搜索结果
    网络连接不上, 有TCP错误, 如果操作系统是Windows Server 2003, 请尝试一下这里
    在WinDBG中查看内存的命令
    The virtual machine could not be started because the hypervisor is not running
  • 原文地址:https://www.cnblogs.com/WNJXYK/p/4067788.html
Copyright © 2011-2022 走看看