点我看题目

题意 : 冒泡排序的原理众所周知,需要扫描很多遍。而现在是求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 快速幂取模+组合数学

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

  3. poj 3761 bubble sort (排列组合)

    #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^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_快速幂

    题意:问你冒泡排序第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. 快速幂取模(POJ 1995)

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

随机推荐

  1. (转)持续化集成工具CruiseControl.NET

    持续化集成工具CC.NET[ 引言: 团队开发需要 进行集中的项目文件管理与有效的协调,我们采用源代码管理工具协助我们管理,卓有成效.限定重要文件的访问权限.使用悲观锁杜绝成员同时编辑同一份文件. 不 ...

  2. jQuery-ui treegird 使用

    在实际应用中可能会碰到不同的需求,比如会根据每行不同的参数或属性设置来设置同列不同的editor类型,这时原有的例子就显的有点太过简单,不能实现我们的需求,现在应用我在项目中的操作为例,显示下实现同列 ...

  3. STL--string(转载)

    string类的构造函数: string(const char *s); //用c字符串s初始化 string(int n,char c); //用n个字符c初始化 此外,string类还支持默认构造 ...

  4. lex&yacc2

    YACC: 每个归约后yacc 都执行默认动作,在运行任何明确的动作代码之前,将值$1 赋介$$. 下面是从这个语法中生成的 y.tab.h:#define NAME 257#define NUMBE ...

  5. C++编译期判断是否能够转型

    #include <iostream> #include <vector> using namespace std; template<class T,class U&g ...

  6. 按按钮调用PHP function函数

    首先,请大家看一段HTML代码: <html> <head> </head> <body> <input type=button on_click ...

  7. Linux 信号量 生产者消费者小例题

    菜鸟偶遇信号量,擦出火花(只有不熟才会有火花).于是上网搜资料和看<Unix环境高级编程>实现了几个小例题,高手请勿喷!这几位写得非常好啊: 题目来源: http://www.it165. ...

  8. Qt 日志宏

    随便写了一个日志帮助的宏,既可以如同qDebug()一般在调试时输出信息,也可以在输出文本文件 #ifndef LOG_H #define LOG_H #include <QDir> #i ...

  9. Export功能 导致 页面显示很多非法字符,还可能页面显示两次

    private void exportBinaryToExcel(byte[] bytes, string filename) { Response.AddHeader("Content-D ...

  10. 前端encodeURIComponent 和后端http_build_query配合

    解决特殊字符不能转义 1.  function fixedEncodeURIComponent (str) {  return encodeURIComponent(str).replace(/[!' ...