博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【BZOJ4870】组合数问题 [矩阵乘法][DP]
阅读量:7066 次
发布时间:2019-06-28

本文共 1058 字,大约阅读时间需要 3 分钟。

组合数问题

Time Limit: 10 Sec  Memory Limit: 512 MB
[][][]

Description

  

Input

  第一行有四个整数 n, p, k, r,所有整数含义见问题描述。

Output

  一行一个整数代表答案。

Sample Input

  2 10007 2 0

Sample Output

  8

HINT

  1 ≤ n ≤ 10^9, 0 ≤ r < k ≤ 50, 2 ≤ p ≤ 2^30 − 1

Solution

  首先,不难发现,题目的本质是:从n*k个中选模k等于r个的方案数,那么轻易地写出了暴力DPf[i][j]=f[i-1][j]+f[i-1][(j-1+k)%k]

  然后套个矩阵乘法优化一下即可。

Code

#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long s64;const int ONE = 55;int n,MOD,num,r;inline s64 get(){ s64 res=1,Q=1; char c; while( (c=getchar())<48 || c>57) if(c=='-')Q=-1; if(Q) res=c-48; while((c=getchar())>=48 && c<=57) res=res*10+c-48; return res*Q; }struct Matrix{ s64 v[ONE][ONE]; friend Matrix operator *(Matrix a,Matrix b) { Matrix record; for(int i=0;i
>=1; } return res;}int main(){ n=get(); MOD=get(); num=get(); r=get(); for(int i=0;i
View Code

 

转载于:https://www.cnblogs.com/BearChild/p/6824207.html

你可能感兴趣的文章
这个路口再次遇见你------单例模式在读取配置文件时的应用
查看>>
c# 操作excel 替代方案
查看>>
创建自定义的菜单与按钮
查看>>
tag标签数据库的设计
查看>>
C#操作sqlite数据库使用SQLiteParameter传递参数
查看>>
slick-pg v0.1.5 发布
查看>>
pygame系列_pygame安装
查看>>
Android开发探秘之二:导入存在的项目及其注意事项
查看>>
每日英语:In Digital Era, What Does 'Watching TV' Even Mean?
查看>>
聚合查询中的Group by
查看>>
/dev/null和/dev/zero的区别
查看>>
MySQL 利用SQL线程对Binlog操作
查看>>
Revit API射线法读取空间中相交的元素
查看>>
浅谈bitmap算法
查看>>
人月数的计算公式
查看>>
Knockout与Require框架同时使用时的visible绑定的问题,造成的影响,以及解决的方法。...
查看>>
Devexpress 之gridControl双击行事件
查看>>
[CLR via C#]1.5 本地代码生成器:NGen.exe
查看>>
Ubuntu 12.04.3 X64 使用 NFS 作为文件共享存储方式 安装 Oracle11g RAC
查看>>
2014第4周六
查看>>