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 res=1;
    while(y){
        if(y&1)res=res*x%mod;
        x=x*x%mod;
        y/=2;
    }
    return res;
}
int main(){
   // cout<<qpow(2,10)<<endl;
    int T;
    scanf("%d",&T);
    for(int cn=1;cn<=T;cn++){
        int n,m,k;
        scanf("%d %d %d",&n,&m,&k);
        ll ans=qpow(k,n*m),res=0;
        for(int i=2;i<=k;i++)
            res=(res+qpow(i-1,n+m-2)*qpow(k,(n-1)*(m-1))%mod)%mod;
        ans=(ans+res*n*m%mod)%mod;
        printf("Case #%d: %lld\n",cn,ans);
    }
    return 0;
}

  

原文地址:https://www.cnblogs.com/carcar/p/11629560.html

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

codeforces#101194H. Great Cells(数学)的相关文章

CodeForces 534C Polycarpus&#39; Dice (数学)

题意:第一行给两个数,n 和 A,n 表示有n 个骰子,A表示 n 个骰子掷出的数的和.第二行给出n个数,表示第n个骰子所能掷出的最大的数,这些骰子都有问题, 可能或多或少的掷不出几个数,输出n个骰子掷不出的数的个数. 析:我们只要考虑两个极端就好,考由其他骰子投出的最大值和最小值,还有自身在最大值和最小值,作一个数学运算就OK了.公式如下: 骰子的最大值-能投的最大值+能投的最小值-1. 代码如下: #include <cstdio> #include <string> #inc

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-

codeforces 701B B. Cells Not Under Attack(水题)

题目链接: B. Cells Not Under Attack 题意: n*n的棋盘,现在放m个棋子,放一个棋子这一行和这一列就不会under attack了,每次放棋子回答有多少点还可能under attack; 思路:对行和列标记; AC代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #incl

Codeforces 468C Hack it!(数学)

题目链接:Codeforces 468C Hack it! 题目大意:给据题目定义,找到l,r,使得solve(l,r) % a = 0. 解题思路:f(x + 1e18) = f(x) + 1,所以有solve(x + 1, x+1e18) = solve(x, x+1e18-1) + 1,假定x为0,我们求出solve(0, 1e18) % a = k,那么a - k,即为区间需要移动的步长.solve(1e18) % a = 4518 1e17 % a #include <cstdio>

Codeforces 520E. Pluses everywhere 数学

520E - Pluses everywhere/521C - Pluses everywhere Idea: Endagorion Preparation: gchebanov, DPR-pavlin Consider some way of placing all the pluses, and a single digit di (digits in the string are numbered starting from 0 from left to right). This digi

Codeforces 688D Remainders Game 数学

题意:Pari选了两个数x,k,已知k和n个数c[i],也能"知道"x%c[i],问是否x%k的值是否唯一?n,k,c[i]<=1e6 假如存在x1,x2满足:x1和x2同余c[i](i=1..n),但是x1%k!=x2%k 则此时不能确定x%k的值,答案为no即(x1-x2)%c[i]==0 因为lcm(c[1]..c[n])|(x1-x2) k不整除(x1-x2) k也不整除lcm(c[1]..c[n]) 该条件为必要条件.证明充分性很简单 构造x1=2*lcm,x2=lcm

Codeforces 17A Noldbach problem(数学)

题意 求n以内等于两个连续素数的和加上1的数的个数 n不大于1000 #include<cstdio> #include<cmath> #include<algorithm> using namespace std; const int N = 1000; int n, k, ans; bool isPrime (int a) { for (int i = 2; i <= sqrt (a); ++i) if (a % i == 0) return 0; retur

codeforces 688D - Remainders Game 数学相关

题意:给你x%ci=bi(x未知),是否能确定x%k的值(k已知) 分析:只要保证k能整除ci的最小公倍数即可,由于太大,所以通过暴力分解因子的办法来判断 #include <cstdio> #include <iostream> #include <ctime> #include <vector> #include <cmath> #include <map> #include <set> #include <st

Codeforces 911D. Inversion Counting (数学、思维)

题目链接:Inversion Counting 题意: 定义数列{ai|i=1,2,...,n}的逆序对如下:对于所有的1≤j<i≤n,若ai<aj,则<i,j>为一个逆序对.于是,对于一个数列a[1..n],给定m次操作.对于每一次操作,给定l,r(1≤l<r≤n),将序列a[l..r]倒置.求倒置后的逆序对的数量的奇偶性. 题解: 假设现在我们有一个序列并翻转这个序列[l,r]区间里面的数.假设某个数的k值是指在这个值后面小于这个数的数的个数,其实我们可以发现对于[1,l