题目链接:

B.Table

题意:

\(n*m\)的矩阵使每个\(n*n\)矩阵里面准确包含\(k\)个点,问你有多少种放法。

\((1 ≤ n ≤ 100; n ≤ m ≤ 10^{18}; 0 ≤ k ≤ n^2)\)

题解:

- Let \(s_i\) number of points in the column \(i\).

- Two neighboring squares are drawn at this picture, \(A\) is the number of point it the left area (it is one column), \(B\) is the number of points in the middle area and \(C\) is the number of points in the right area (it is one column too). That's why by definition we ###have:

- Therefore \(A = C\).

- That's why

- Divide all columns by equivalence classes on the basis of \(i \mod n\) . For all \(a\) and \(b\) from one class \(s_a = s_b\).

cnta is number of columns in class with

- There are \(C(n,k)^{cnt_a}\) ways to draw \(k\) points in the each of columns in the class \(a\) independendently of the other classes.

- \(dp[i][j]\) is number of ways to fill all columns in classes \(1, ... i\) in such way that .

- \(cnt_i\) take only two values and

. Let's calc \(C(n,a)^{cnt_i}\) for all \(a\) and \(cnt_i\) and use it to calc our dp. We have \(O(n^2·k)\) complexity.

代码:

#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
const int N = 123;
const int K = 10000+1230;
ll pow1[N],pow2[N];
ll dp[N][K];
ll c[N][N]; //n*m的矩阵使每个n*n矩阵里面准确包含k个点,问你有多少种放法。 ll quick_pow(ll a,ll b)
{
ll tmp=a;
ll ans=1;
while(b)
{
if(b&1) ans=(ans*tmp)%mod;
tmp=(tmp*tmp)%mod;
b>>=1;
}
return ans;
}
int main()
{
int n,k;
ll m;
cin>>n>>m>>k;
for(int i=0;i<=n;i++) c[i][0]=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
}
}
for(int i=0;i<=n;i++)
{
pow1[i]=quick_pow(c[n][i],m/n);
pow2[i]=(pow1[i]*c[n][i])%mod;
}
dp[0][0]=1;
ll now;
for(int i=0;i<n;i++)
{
for(int j=0;j<=k;j++)
{
if(dp[i][j]!=0)
{
for(int p = 0;p <= n && j + p <= k;p++)
{
if(i<m%n) now=pow2[p];
else now=pow1[p]; dp[i+1][j+p]=(dp[i+1][j+p]+dp[i][j]*now)%mod;
}
}
} }
cout<<dp[n][k]<<endl;
return 0;
}

Codeforces #144 (Div. 1) B. Table (组合数学+dp)的更多相关文章

  1. Codeforces Round #345 (Div. 1) C. Table Compression dp+并查集

    题目链接: http://codeforces.com/problemset/problem/650/C C. Table Compression time limit per test4 secon ...

  2. Codeforces Round #144 (Div. 2) D table

    CodeForces - 233D 题目大意给你一个n*m 的矩阵,要求你进行涂色,保证每个n*n的矩阵内都有k个点被涂色. 问你一共有多少种涂色方案. n<=100 && m& ...

  3. Codeforces Gym 100338H High Speed Trains 组合数学+dp+高精度

    原题链接:http://codeforces.com/gym/100338/attachments/download/2136/20062007-winter-petrozavodsk-camp-an ...

  4. codeforces 869C The Intriguing Obsession【组合数学+dp+第二类斯特林公式】

    C. The Intriguing Obsession time limit per test 1 second memory limit per test 256 megabytes input s ...

  5. 贪心 Codeforces Round #273 (Div. 2) C. Table Decorations

    题目传送门 /* 贪心:排序后,当a[3] > 2 * (a[1] + a[2]), 可以最多的2个,其他的都是1个,ggr,ggb, ggr... ans = a[1] + a[2]; 或先2 ...

  6. Codeforces #345 Div.1

    Codeforces #345 Div.1 打CF有助于提高做题的正确率. Watchmen 题目描述:求欧拉距离等于曼哈顿距离的点对个数. solution 签到题,其实就是求有多少对点在同一行或同 ...

  7. [CodeForces - 1272D] Remove One Element 【线性dp】

    [CodeForces - 1272D] Remove One Element [线性dp] 标签:题解 codeforces题解 dp 线性dp 题目描述 Time limit 2000 ms Me ...

  8. 让div中的table居中

    div 标签上写  style="text-align:center" div中的table中写 style="margin:auto;"  <table ...

  9. Codeforces 219D. Choosing Capital for Treeland (树dp)

    题目链接:http://codeforces.com/contest/219/problem/D 树dp //#pragma comment(linker, "/STACK:10240000 ...

随机推荐

  1. cogs 1430. [UVa 11300]分金币

    1430. [UVa 11300]分金币 ★☆   输入文件:Wealth.in   输出文件:Wealth.out   简单对比时间限制:1 s   内存限制:256 MB [题目描述] 圆桌旁坐着 ...

  2. es6 --- Generator 函数

    第一部分,ES6 中的 Generator 在 ES6 出现之前,基本都是各式各样类似Promise的解决方案来处理异步操作的代码逻辑,但是 ES6 的Generator却给异步操作又提供了新的思路, ...

  3. Spring boot 解析jsp支持jsp热部署

    解析jsp并且支持jsp热部署 参考地址:https://www.wanpishe.top/detail?blogId=39875536-7d45-48ec-a7b5-f36b85c3a235

  4. readonly&&declare&&unset &&export&&env环境变量

    readonly命令用于定义只读shell变量和shell函数.readonly命令的选项-p可以输出显示系统中所有定义的只读变量. 选项 -f:定义只读函数: -a:定义只读数组变量: -p:显示系 ...

  5. IDLE的自动补全功能

    IDLE的自动补全功能位于:Edit→Show Completions,但每次需要补全的时候都需要点击一次,虽然IDLE提供了一个快捷键(Ctrl + Space),但实测无效.具体操作如下图

  6. CMDB学习之一

    CMDB - 配置管理数据库 资产管理 自动化相关的平台(基础 CMDB): 1. 发布系统 2. 监控 3. 配管系统.装机 4. 堡垒机 CMDB的目的: 1. 替代EXCEL资产管理 —— 资产 ...

  7. C#学习第一课

    C#和Java存在很多相似之处,但是也存在一些差异.今天下午刚去图书馆借了C#的入门书籍,进过简单的入门,我了解了几点不同之处: 1. Java中的基本数据类型只有8种,数据类型不存在无符号和有符号的 ...

  8. 让JavaScript在Visual Studio 2015中编辑得更easy

    微软公布的Visual Studio 2015展示了该公司对于让该开发工具更好的支持主流的开发语言的工作.微软项目经理Jordan Matthiesen已经具体列出了一些具体处理JavaScript开 ...

  9. LeetCode_ZigZag Conversion

    一.题目 ZigZag Conversion Total Accepted: 31399 Total Submissions: 140315My Submissions The string &quo ...

  10. tcpdump重要笔记

    无关痛痒的參数就不写了.仅仅说一些我觉得值得注意的. 1 tcpdump參数 -s 最早在公司旧机器上截包时发现总是不完整,于是知道了这个參数,之后就一直用-s0了.近期一次在家里,忘记输入-s发现包 ...