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

    2751: [HAOI2012]容易题(easy)

    Time Limit: 10 Sec  Memory Limit: 128 MB
    Submit: 872  Solved: 377
    [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

    Source

    题解:

    一眼题,不解释。。。

    不在家,map记不下来。。。

    代码:(copy)

     1 #include<cstdio>
     2 #include<algorithm>
     3 using namespace std;
     4 #define LL long long
     5 #define mod 1000000007
     6 #define K 100010
     7 struct lim{
     8     int x,y;
     9 }l[K];
    10 LL n,m,tot,ans=1,mul,tomul;
    11 int k,cnt;
    12 inline bool cmp(const lim &a,const lim &b)
    13 {return a.x<b.x||a.x==b.x&&a.y<b.y;}
    14 inline void quickpow(LL &ans,LL a,LL b)
    15 {
    16     LL mult=a;
    17     while (b)
    18     {
    19         if (b&1)ans=(ans*mult)%mod;
    20         mult=(mult*mult)%mod;
    21         b>>=1;
    22     }
    23 }
    24 inline LL read()
    25 {
    26     LL x=0,f=1;char ch=getchar();
    27     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    28     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    29     return x*f;
    30 }
    31 int main()
    32 {
    33     n=read();m=read();k=read();mul=(n*(n+1)/2)%mod;
    34     LL x,y;
    35     for(int i=1;i<=k;i++)
    36     {
    37         l[i].x=read();l[i].y=read();
    38     }
    39     sort(l+1,l+k+1,cmp);
    40     tot=m;tomul=mul-l[1].y;
    41     for (int i=2;i<=k;i++)
    42     {
    43         if (l[i].x==l[i-1].x)
    44         {
    45             if (l[i].y==l[i-1].y)continue;
    46             tomul-=l[i].y;
    47         }else
    48         {
    49             tot--;
    50             if (tomul<0)tomul=tomul%mod+mod;
    51             ans=(ans*tomul)%mod;
    52             tomul=mul-l[i].y;
    53         }
    54     }
    55     if (mul!=tomul)
    56     {
    57         tot--;
    58         if (tomul<0)tomul=tomul%mod+mod;
    59         ans=(ans*tomul)%mod;
    60     }
    61     quickpow(ans,mul,tot);
    62     printf("%lld",ans);
    63 }
    View Code
  • 相关阅读:
    Springboot中使用ibatis输出日志
    openssl生成iis需要的pfx格式的证书
    SpringBoot 默认日志
    Spring @Value 默认值
    SpringBoot+MyBatis中自动根据@Table注解和@Column注解生成增删改查逻辑
    geomesa hbase geoserver
    在hyper-v中安装centos后配置网络
    linux命令
    SpringBoot+MyBatis中自动根据@Table注解和@Column注解生成ResultMap
    Java 获取指定包下的所有类
  • 原文地址:https://www.cnblogs.com/zyfzyf/p/3981929.html
Copyright © 2011-2022 走看看