POJ 3761 Bubble Sort(乘方取模)

时间:2021-04-07 10:16:57

点我看题目

题意 : 冒泡排序的原理众所周知,需要扫描很多遍。而现在是求1到n的各种排列中,需要扫描k遍就变为有序的数列的个数,结果模20100713,当然了,只要数列有序就扫描结束,不需要像真正的冒泡排序要扫描n-1遍。

思路 : 这个题的结果是K!((K + 1) ^ (N - K) - K ^ (N - K))。需要用到逆序数,此题具体推导

 //POJ 3761
#include <iostream>
#include <stdio.h>
#include <string.h> using namespace std;
const __int64 mod = 20100713LL ;
__int64 factorial[] ; void chart()
{
factorial[] = factorial[] = ;
for(int i = ; i <= ; i++)
factorial[i] = factorial[i-]*i % mod ;
} __int64 multimod(__int64 x,__int64 n )
{
__int64 tmp = x ,res = 1LL ;
while(n)
{
if(n & 1LL)
{
res *= tmp ;
res %= mod ;
}
tmp *= tmp ;
tmp %= mod ;
n >>= 1LL ;
}
return res ;
}
int main()
{
__int64 t,n,k ;
__int64 ans1,ans2,ans ;
chart() ;
scanf("%I64d",&t) ;
while(t--)
{
scanf("%I64d %I64d",&n,&k) ;
if(k == ) {
printf("1\n") ;
continue ;
}
ans1 = ans2 = factorial[k] ;
ans1 *= multimod(k+,n-k) ;
ans1 %= mod ;
ans1 += mod ;
ans2 *= multimod(k,n-k) ;
ans2 %= mod ;
ans = (ans1-ans2)%mod ;
printf("%I64d\n",ans) ;
}
return ;
}

POJ 3761 Bubble Sort(乘方取模)的更多相关文章

  1. 快速幂取模 POJ 3761 bubble sort

    题目传送门 /* 题意:求冒泡排序扫描k次能排好序的全排列个数 数学:这里有一个反序列表的概念,bj表示在j左边,但大于j的个数.不多说了,我也是看网上的解题报告. 详细解释:http://blog. ...

  2. POJ 3761 Bubble Sort 快速幂取模&plus;组合数学

    转载于:http://www.cnblogs.com/767355675hutaishi/p/3873770.html 题目大意:众所周知冒泡排序算法多数情况下不能只扫描一遍就结束排序,而是要扫描好几 ...

  3. poj 3761 bubble sort &lpar;排列组合&rpar;

    #include<cstdio> #include<cstring> #define ll long long #define mod 20100713 ; ll a[maxn ...

  4. POJ 3761 Bubble Sort

    题目链接:https://vjudge.net/problem/POJ-3761 转自:https://blog.csdn.net/cscj2010/article/details/7820906 题 ...

  5. Codevs 5208 求乘方取模

    5208 求乘方取模 时间限制: 1 s 空间限制: 1000 KB 题目等级 : 未定级 题目描述 Description 给定非负整数A.B.M,求(A ^ B) mod M. 输入描述 Inpu ...

  6. E - A&Hat;B mod C (大数乘方取模)

    Description Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,B,C<2^63) ...

  7. poj 3761 Bubble Sort&lowbar;快速幂

    题意:问你冒泡排序第i次排序,一共排了多少次 套公式K!((K + 1) ^ (N - K) - K ^ (N - K)) #include <iostream> #include< ...

  8. poj 2065 高斯消元(取模的方程组)

    SETI Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 1735   Accepted: 1085 Description ...

  9. 快速幂取模&lpar;POJ 1995&rpar;

    http://poj.org/problem?id=1995 以这道题来分析一下快速幂取模 a^b%c(这就是著名的RSA公钥的加密方法),当a,b很大时,直接求解这个问题不太可能 利用公式a*b%c ...

随机推荐

  1. Ubuntu 网络参数设置

    修改网络设置 sudo vim /etc/network/interfaces 修改计算机名 sudo vim /etc/hostname sudo vim /etc/hosts

  2. 生成Geometry

    // 由一组点集生成一张三角面片网格Geometry osg::Geometry* createTRIANGLESGeometry(MyMesh &mesh) { osg::ref_ptr&l ...

  3. 新浪微博之XSS蠕虫脚本源码讲解

    主要是因为新浪的广场页面有几个链接对输入参数过滤不严导致的反射性XSS.======================================== 微博XSS漏洞点 weibo.com/pub/ ...

  4. node搜索codeforces 3A - Shortest path of the king

    发一下牢骚和主题无关: 搜索,最短路都可以     每日一道理 人生是洁白的画纸,我们每个人就是手握各色笔的画师:人生也是一条看不到尽头的长路,我们每个人则是人生道路的远足者:人生还像是一块神奇的土地 ...

  5. Linux apt-get error

    csh@csh-laptop:~/ejabberd-15.03$ sudo apt-get install mysqlReading package lists... DoneBuilding dep ...

  6. Python - 安装并配置Anaconda环境

    1- 简介 官网:https://www.anaconda.com/ Anaconda是一个用于科学计算的Python发行版,适用于数据分析的Python工具,也可以用在大数据和人工智能领域. 支持 ...

  7. Vue-动态修改数组

    需求描述: 点击删除时,仅删除当前选中的这个对象. html: <el-card shadow="never" style="position: relative; ...

  8. 潭州课堂25班:Ph201805201 第十六课 正则 &lpar;课堂笔记&rpar;

    import re 元字符: . ^ $ * + ? {} \ () # s = 'abcdefg' # s.find('c') # print(s.find('cd')) ## 查找 # b = s ...

  9. soapui not supported the auto complete

    http://forum.soapui.org/viewtopic.php?t=19850 syntax highlighting or content assist inside soapUI? t ...

  10. Go Web编程 第四章--处理请求

    请求和响应 Request结构 URL字段 Header字段 Body字段 Form, PostForm, MultipartForm字段 在处理器函数中,我们可以通过Request获取各个字段的详细 ...