UVA 11481 - Arrange the Numbers 数学】的更多相关文章

Consider this sequence {1, 2, 3, . . . , N}, as a initial sequence of first N natural numbers. You canearrange this sequence in many ways. There will be N! different arrangements. You have to calculatethe number of arrangement of first N natural numbers…
题意:长度为n的序列,前m位恰好k位正确排序,求方法数 前m位选k个数正确排,为cm[m][k],剩余m - k个空位,要错排,这m - k个数可能是前m个数中剩下的,也可能来自后面的n - m个数 考虑这样一个问题,共n个数,前i位错排的方法数,显然dp[i][0] = i! 递推考虑:处理到第i个数时,等价于前i - 1个数错排的方法数减去在前i - 1个数错排的情况下第i位恰好为i的方法数,后者相当于n - 1个数前i - 1位错排 所以 dp[n][i] = dp[n][i - 1] -…
题意:给定 n,m,k,问你在 1 ~ n 的排列中,前 m 个恰好有 k 个不在自己位置的排列有多少个. 析:枚举 m+1 ~ n 中有多少个恰好在自己位置,这个是C(n-m, i),然后前面选出 k 个,是C(m, k),剩下 n - k - i 个是都不在自己位置,也就是错排 D[n-k-i],求一个和就Ok了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio>…
Colossal Fibonacci Numbers 想先说下最近的状态吧,已经考完试了,这个暑假也应该是最后刷题的暑假了,打完今年acm就应该会退了,但是还什么都不会呢? +_+ 所以这个暑假,一定要竭尽全力地去刷题,当然,也是能好好刷题的最后时间了. [题目链接]Colossal Fibonacci Numbers [题目类型]数学 &题意: 求Fi(f(a^b)%n) Fi()是斐波那契 &题解: 注意:unsigned时 要把%d全换成%u 数学大法好. 首先你要能看出来这是有循环…
题目链接:uva 10712 - Count the Numbers 题目大意:给出n,a.b.问说在a到b之间有多少个n. 解题思路:数位dp.dp[i][j][x][y]表示第i位为j的时候.x是否前面是相等的.y是否已经出现过n.对于n=0的情况要特殊处理前导0,写的很乱.搓死. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using nam…
UVA 10539 - Almost Prime Numbers 题目链接 题意:给定一个区间,求这个区间中的Almost prime number,Almost prime number的定义为:仅仅能整除一个素数. 思路:既然是仅仅能整除一个素数,那么这些数肯定为素数的x次方(x > 1),那么仅仅要先打出素数表,然后在素数表上暴力找一遍就能够了,由于素数表仅仅要找到sqrt(Max),大概100W,然后每一个数找的复杂度为log(n),这样复杂度是能够接受的. 代码: #include <…
1095 - Arrange the Numbers Consider this sequence {1, 2, 3 ... N}, as an initial sequence of first N natural numbers. You can rearrange this sequence in many ways. There will be a total of N! arrangements. You have to calculate the number of arrangem…
居然没有往错排公式那去想,真是太弱了. 先在前m个数中挑出k个位置不变的数,有C(m, k)种方案,然后枚举后面n-m个位置不变的数的个数i,剩下的n-k-i个数就是错排了. 所以这里要递推一个组合数和错排数. 顺便再复习一下错排递推公式,Dn = (n-1)(Dn-1 + Dn-2),D0 = 1,D1 = 0. 这里强调一下D0的值,我之前就是因为直接从D1和D2开始递推的结果WA #include <cstdio> typedef long long LL; + ; ; LL c[max…
A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example,the name “anna” is a palindrome. Numbers can also be palindromes (e.g. 151 or 753357). Additionallynumbers can of course be ordered in size. The first few…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2456 题目大意: 给出两个数a,b(a<=b<=100000),求在a和b之间有多少个完全平方数(包括a和b) 思路: 打表啊打表. #include<cstdio> #include<cstring> #include<cmath> cons…