【Hackerrank 101Hack 43】【JZOJ5135】K-Inversion Permutations 题解
来源:互联网 发布:指纹 门禁锁 知乎 编辑:程序博客网 时间:2024/05/16 11:19
题目大意
【50%】n, k<=1000
【100%解法1】
以上抄自 WerKeyTom_FTD 给的笔记,我还没学会
【100%解法2】
代码
//解法2
#include<cmath>#include<cstdio>#include<algorithm>#define fo(i,a,b) for(int i=a;i<=b;i++)#define fd(i,a,b) for(int i=a;i>=b;i--)using namespace std;typedef long long LL;const int maxn=1e5+5, maxsqrtk=448;const LL mo=1e9+7;int n,k;LL fac[2*maxn],ny[2*maxn];LL mi(LL x,LL y){ LL re=1; for(; y; y>>=1, x=x*x%mo) if (y&1) re=re*x%mo; return re;}void C_Pre(int n){ fac[0]=ny[0]=1; fo(i,1,n) fac[i]=fac[i-1]*i%mo; ny[n]=mi(fac[n],mo-2); fd(i,n-1,1) ny[i]=ny[i+1]*(i+1)%mo;}LL C(int n,int m) {return fac[n]*ny[m]%mo*ny[n-m]%mo;}LL f[maxsqrtk+2][maxn],g[maxn];int main(){ scanf("%d %d",&n,&k); C_Pre(2*max(n,k)); f[0][0]=g[0]=1; fo(i,1,maxsqrtk) fo(j,1,k) { if (j>=i) (f[i][j]-=f[i-1][j-i])%=mo; // 新加一个大小为1的物品 if (j>=i) (f[i][j]+=f[i][j-i])%=mo; // 全体+1 if (j>=n+1) (f[i][j]+=f[i-1][j-(n+1)])%=mo; (g[j]+=f[i][j])%=mo; } LL ans=0; fo(i,0,k) (ans+=g[i]*C(k-i+n-1,n-1))%=mo; printf("%lld\n",(ans+mo)%mo);}
- 【Hackerrank 101Hack 43】【JZOJ5135】K-Inversion Permutations 题解
- [JZOJ5135]逆序对/[HackerRank-101hack43]K-Inversion Permutations
- [Hackerrank 101 Hack 43&& MenciOJ P321] K-Inversion Permutations
- Hackerrank 101 Hack 42 Array Pairs
- [HackerRank 101 Hack 42]Array Pairs
- [HackerRank 101 Hack 51] Train Trip
- [HackerRank 101 Hack 51] Small Cubes
- [HackerRank 101 Hack 51] Testing the Game
- [hackerrank Value of all Permutations]
- [Hackerrank-algorithm-warmup]题解
- hackerrank Hourrank16题解
- HackerRank Twin Arrays 题解
- HackerRank Pattern Count 题解
- [线段树][单调栈]HackerRank 101 Hack 50 .Boxes for Toys
- [线段树 || 主席树][Hash] HackerRank 101 Hack 49. Sorting Lists
- Hackerrank - Game Of Rotation 题解
- 【Hackerrank World11】Road Trip 题解
- codechef Ambiguous Permutations 题解
- NumPy
- webapi token、参数签名是如何生成的
- Machine Learning_安装_tensorflow
- opencv输出特征数据、libsvm进行图像分类输出置信度、matlab输出ROC曲线
- 如何使用 Android O 的自动填充框架
- 【Hackerrank 101Hack 43】【JZOJ5135】K-Inversion Permutations 题解
- 1347 旋转字符串
- 守时
- Redhat6.5网络配置
- 解决web.xml is missing and <failOnMissingWebXml> is set to true问题
- Tensorflow-2-Tensorboard使用
- 还是学C++吧
- Python 基础 def函数
- Git错误之无法连接github