Problem H. Great Cells

题目链接:https://codeforces.com/gym/101194/attachments

Input file: Standard Input

Output file: Standard Ouptut

Time limit: 2 seconds

题目大意:

在N×M的网格里填[1,K]的整数,如果满足这个格子中的数是本行和本列中严格的最大值,定义这个格子是great的。定义A-g为网格中恰好有g个great格子的填法数,求Σ(g+1)A-g(mod1e9+7). 0<=g<=N*M

解题思路:

将式子分为两部分,一部分是Σ(A-g),另一部分是Σ(g*A-g).前一部分是指有0个great到n*m个great的之和。也就是在网格中任意填的所有情况,即K^(n*m)。而后一部份是指有g个great时,累加上g个great的所有放法并乘上g。其实可以认为,认为放法为num,num=(1+1+1+1+....),g*num=g*(1+1+1+1...)=g+g+g+g+g+......。每一种放法将会放g个,所以只要当这一格是great时那么,这一格就加1。最后将每个方格的数加起来,当然这样不可行,不过分析后可以知道每个格的数值其实就是它是great的所有情况总和。而如果这个格是great,那么同行同列的小格就一定小于它放的数值,而其他的可以任意填。所以枚举其中一个格放的数值即可。即Σ( ksm(i,n-1+m-1) * ksm( k,(n-1)*(m-1) ) ).1<=i<k。所以其后半部分总和就是n*m*Σ( ksm(i,n-1+m-1) * ksm( k,(n-1)*(m-1) ) ) 1<=i<k

代码:

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=;
ll ksm(ll a,ll b){
ll sum=;
while(b){
if(b&)
sum=sum*a%mod;
a=a*a%mod;
b>>=;
}
return sum;
} int main(){
ll t,n,m,k;
ll ans,ans1,ans2=,count=;
cin>>t;
while(t--){
count++;
ans2=;
cin>>n>>m>>k;
ans1=ksm(k,n*m);
for(ll i=;i<k;i++){
ans2=(ans2+(ksm(i,n-+m-)*ksm(k,(m-)*(n-))%mod))%mod;
}
ans=(ans1+m*n*ans2%mod)%mod;
printf("Case #%lld: %lld\n",count,ans);
}
return ;
}

如果有错误请评论指出

Gym - 101194H Great Cells的更多相关文章

  1. Gym 101194H / UVALive 7904 - Great Cells - [数学题+快速幂][2016 EC-Final Problem H]

    题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...

  2. codeforces#101194H. Great Cells(数学)

    题目链接: https://codeforces.com/gym/101194 题意: 在$n×m$的各自中填上$1$到$k$的数 定义Greate cell为严格大于同行和同列的格子 定义$A_g$ ...

  3. 2016-2017 ACM-ICPC CHINA-Final

    A Gym 101194A Number Theory Problem 7 的二进制是111,2k-1 的二进制是 k 个 1.所以 k 能被 3 整除时 2k-1 才能被 7 整除. #includ ...

  4. CF [2016-2017 ACM-ICPC CHINA-Final][GYM 101194 H] Great Cells

    很久以前做的一道思博题了,今天来补一补. 大致题意:在一个\(n*m\)的矩阵内填整数,数字在\([1,k]\)范围内.矩阵中某格的数为great number当且仅当与它同行同列的数字都严格比它小. ...

  5. Gym 101102D---Rectangles(单调栈)

    题目链接 http://codeforces.com/gym/101102/problem/D problem  description Given an R×C grid with each cel ...

  6. Codeforces Gym 100187E E. Two Labyrinths bfs

    E. Two Labyrinths Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/prob ...

  7. Codeforces GYM 100114 B. Island 水题

    B. Island Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Description O ...

  8. Gym 101981K - Kangaroo Puzzle - [玄学][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem K]

    题目链接:http://codeforces.com/gym/101981/problem/K Your friend has made a computer video game called “K ...

  9. Gym 100971J-Robots at Warehouse

    题目链接:http://codeforces.com/gym/100971/problem/J Vitaly works at the warehouse. The warehouse can be ...

随机推荐

  1. adbl连接不上 daemon not running. starting it now on port 5037 ADB server didn't ACK

     http://blog.csdn.net/prettyice2005/article/details/38682443 adbl连接不上 daemon not running. starting i ...

  2. golang md5 结果类型

    golang  md5 结果类型 package main import ( "crypto/md5" "encoding/hex" "fmt&quo ...

  3. Nginx 日志切割(Logrotate)

    Logrotate 配置文件 # ls /etc/logrotate.* /etc/logrotate.conf /etc/logrotate.d: cups dracut fmdcn httpd i ...

  4. CentOS 6 安装Syslog-ng

    entOS 6 安装 Syslog-ng 一. yum 安装 syslog-ng3.7.1 是专门用于RHEL/CentOS version 6 ,不要安装成其他版本.亲身经历,安装成syslog-n ...

  5. 通过命令直接修改jar包中的静态文件

    1.先将要修改的jar包备份 copy xxx.jar xxx.jar_bak 2.建立一个新的目录便于后面的打包 mkdir jar_tmp 3.将包放到刚刚创建的目录里解压 mv xxx.jar ...

  6. 【MM系列】SAP MM模块-委外采购订单 把Warning转换成Error信息提示

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP MM模块-委外采购订单 把W ...

  7. vue打包详情

    说明 本文代码中的配置基于vue-cli2 需求 在实际开发中我们可能有测试环境一套请求API 和 正式环境一套API,尤其是两个环境的域名不同时,就需要我们分环境打不同配置的包 了解 webpack ...

  8. glibc升级,解决glib版本过低的问题

    Debian wheezy下的glibc版本为2.13,安装几个软件都运行不了,报以下类似错误:xxxx: /lib/i386-linux-gnu/i686/cmov/libc.so.6: versi ...

  9. tips for using shortcuts

    tips for using shortcuts for mac: command+ctrl+F:full screen(当前应用全屏之后有一个好处 就是 使用 4 tap 的手势 可以在全屏的界面之 ...

  10. Java高级数据类型转换:包装类、String字符串、Date类等与其他类型转换

    1.包装类过渡类型转换 一般情况下,我们首先声明一个变量,然后生成一个对应的包装类,就可以利用包装类的各种方法进行类型转换了.例如: 当希望把float型转换为double型时: float f1=1 ...