POJ 3761 Bubble Sort】的更多相关文章

题目传送门 /* 题意:求冒泡排序扫描k次能排好序的全排列个数 数学:这里有一个反序列表的概念,bj表示在j左边,但大于j的个数.不多说了,我也是看网上的解题报告. 详细解释:http://blog.csdn.net/cscj2010/article/details/7820906 */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using names…
点我看题目 题意 : 冒泡排序的原理众所周知,需要扫描很多遍.而现在是求1到n的各种排列中,需要扫描k遍就变为有序的数列的个数,结果模20100713,当然了,只要数列有序就扫描结束,不需要像真正的冒泡排序要扫描n-1遍. 思路 : 这个题的结果是K!((K + 1) ^ (N - K) - K ^ (N - K)).需要用到逆序数,此题具体推导. //POJ 3761 #include <iostream> #include <stdio.h> #include <stri…
转载于:http://www.cnblogs.com/767355675hutaishi/p/3873770.html 题目大意:众所周知冒泡排序算法多数情况下不能只扫描一遍就结束排序,而是要扫描好几遍.现在你的任务是求1~N的排列中,需要扫描K遍才能排好序的数列的个数模20100713.注意,不同于真正的冒泡排序算法,只要数列有序就立刻停止,而不用再检验一遍. 估计多数人都是找规律吧,先看出递推,然后求出通项……这个题只有找出通项公式才能通过,所以首先公布答案: K!((K + 1) ^ (N…
#include<cstdio> #include<cstring> #define ll long long #define mod 20100713 ; ll a[maxn]; ll poww(ll x,int n) { ll ret=; while(n) { ) ret=ret*x%mod; n>>=; x=x*x%mod; } return ret; } int main() { a[]=; ;i<maxn;i++) a[i]=a[i-]*i%mod; i…
题目链接:https://vjudge.net/problem/POJ-3761 转自:https://blog.csdn.net/cscj2010/article/details/7820906 题目大意   含 n 个不同元素的排列恰好经过 k 趟冒泡排序变得有序.问原数组有多少种排列情况? 分析 第一眼看上去觉得是个 DP,最后发现是个数学题,认栽... 首先,定义 f(x) 表示在数组中位于元素 x 左面且大于 x 的个数.那么有$0 \leq f(x) \leq n - x$. 定义…
题意:问你冒泡排序第i次排序,一共排了多少次 套公式K!((K + 1) ^ (N - K) - K ^ (N - K)) #include <iostream> #include<cstdio> #include<cstring> using namespace std; #define LL long long #define N 1000010 #define M 20100713 LL a[N]; int _pow(LL v,int k){ LL res=1;…
Java中的经典算法之冒泡排序(Bubble Sort) 神话丿小王子的博客主页 原理:比较两个相邻的元素,将值大的元素交换至右端. 思路:依次比较相邻的两个数,将小数放在前面,大数放在后面.即在第一趟:首先比较第1个和第2个数,将小数放前,大数放后.然后比较第2个数和第3个数,将小数放前,大数放后,如此继续,直至比较最后两个数,将小数放前,大数放后.重复第一趟步骤,直至全部排序完成. 举例说明:要排序数组:int[] arr={6,3,8,2,9,1}; 第一趟排序: 比较,6大于3,交换位置…
Bubble Sort Problem Description   P is a permutation of the integers from 1 to N(index starting from 1).Here is the code of Bubble Sort in C++. for(int i=1;i<=N;++i) for(int j=N,t;j>i;—j) if(P[j-1] > P[j]) t=P[j],P[j]=P[j-1],P[j-1]=t; After the s…
# Program: Bubble sort # Language: MIPS Assembly (32-bit) # Arguments: 5 unordered numbers stored in $2 ~ $6 reg # Author: brant-ruan # Date: 2016-03-10 # IDE: MARS 4.5 # P.S. # This program is one of my homework and the number of assembly instructio…
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-size: 10.5000pt } h1 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: center; font-family: 宋体; color: rgb(26,92,200); font-weight: bold; fo…