Gym - 101194H Great Cells

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

Problem H. Great Cells

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

代码:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const ll mod=1000000007;
 5 ll ksm(ll a,ll b){
 6     ll sum=1;
 7     while(b){
 8         if(b&1)
 9             sum=sum*a%mod;
10         a=a*a%mod;
11         b>>=1;
12     }
13     return sum;
14 }
15
16 int main(){
17     ll t,n,m,k;
18     ll ans,ans1,ans2=0,count=0;
19     cin>>t;
20     while(t--){
21         count++;
22         ans2=0;
23         cin>>n>>m>>k;
24         ans1=ksm(k,n*m);
25         for(ll i=1;i<k;i++){
26             ans2=(ans2+(ksm(i,n-1+m-1)*ksm(k,(m-1)*(n-1))%mod))%mod;
27         }
28         ans=(ans1+m*n*ans2%mod)%mod;
29         printf("Case #%lld: %lld\n",count,ans);
30     }
31     return 0;
32 } 

如果有错误请评论指出

原文地址:https://www.cnblogs.com/meanttobe/p/11626130.html

时间: 2024-08-05 08:32:40

Gym - 101194H Great Cells的相关文章

codeforces#101194H. Great Cells(数学)

题目链接: 题意: 数据范围: $1\leq |S| \leq 1000 000$ 分析: AC代码: #include<bits/stdc++.h> #define ll long long #define pic pair<int,char> #define pii pair<int,int> using namespace std; const int maxn=3e5+7; const int mod=1e9+7; ll qpow(ll x,ll y){ ll

2016-2017 ACM-ICPC CHINA-Final

A Gym 101194A Number Theory Problem B Gym 101194B Hemi Palindrome C Gym 101194C Mr. Panda and Strips D Gym 101194D Ice Cream Tower E Gym 101194E Bet F Gym 101194F Mr. Panda and Fantastic Beasts G Gym 101194G Pandaria H Gym 101194H Great Cells I Gym 1

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

很久以前做的一道思博题了,今天来补一补. 大致题意:在一个\(n*m\)的矩阵内填整数,数字在\([1,k]\)范围内.矩阵中某格的数为great number当且仅当与它同行同列的数字都严格比它小.记\(A_g\)为矩阵中恰有\(g\)个great number的填数方案数,求\(\sum_{g=0}^{nm}(g+1)\cdot A_g\).(\(n,m,k\le200\)) 首先我们可以看出,上界必定是\(min(n,m)\),这个不解释了吧 而又有一个性质,\(\sum_{g=0}^{m

Codeforces Gym 100187E E. Two Labyrinths bfs

E. Two Labyrinths Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/E Description A labyrinth is the rectangular grid, each of the cells of which is either free or wall, and it's possible to move only between free

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

题目链接 http://codeforces.com/gym/101102/problem/D problem  description Given an R×C grid with each cell containing an integer, find the number of subrectangles in this grid that contain only one distinct integer; this means every cell in a subrectangle

Codeforces GYM 100114 B. Island 水题

B. Island Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Description On February 30th this year astronauts from the International Space Station flew over the Pacific Ocean and took a picture, on which was discovered a pr

G - BFS Gym - 101755H

题目:G - BFS Gym - 101755H You play a new RPG. The world map in it is represented by a grid of n × m cells. Any playing character staying in some cell can move from this cell in four directions — to the cells to the left, right, forward and back, but n

单细胞文章分享:Molecular Diversity of Midbrain Development in Mouse, Human, and Stem Cells

Molecular Diversity of Midbrain Development in Mouse, Human, and Stem Cells 本文作者的官网:Ventral midbrain 顺便找到了:Download all the data and Python Notebooks from GitHub to reproduce the main figures. GitHub:linnarsson-lab/ipynb-lamanno2016 教程:scRNA-Seq Data

CodeForces Gym 100935D Enormous Carpet 快速幂取模

Enormous Carpet Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Gym 100935D Description standard input/outputStatements Ameer is an upcoming and pretty talented problem solver who loves to solve problems using computers.