码迷,mamicode.com
首页 > 其他好文 > 详细

PERMUTATION

时间:2016-10-29 19:34:11      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:个数   i++   逆序对   color   nbsp   答案   多少   space   ace   


DESCRIPTION:
从1到n一共n个数字组成的所有排列中,逆序对个数为k的有多少个。
INPUT:
第一行为一个整数T(<10),以下T 行,每行两个整数n(<1000),k(<1000),意义如题目所述。
OUTPUT:
对每组数据输出答案对10000 取模后的结果
SAMPLE INPUT:
1
4 1
SAMPLE OUTPUT:
3

 

#include<cstdio>
using namespace std;
int main()
{
    freopen("permut.in","r",stdin);
    freopen("permut.out","w",stdout);
    int t(0),n(0),k(0);
    static int f[1001][1001];
    for(int i=0;i<=1000;i++)
        f[i][0]=1;
    for(int i=1;i<=1000;i++)
        for(int j=1;j<=1000;j++)
        {
            if(i>j)f[i][j]=(f[i-1][j]+f[i][j-1])%10000;
            else f[i][j]=(f[i-1][j]+f[i][j-1]-f[i-1][j-i]+10000)%10000;
        }
    scanf("%d",&t);
    while(t)
    {
        t--;
        scanf("%d%d",&n,&k);
        printf("%d\n",f[n][k]);
    }
    return 0;
}

PERMUTATION

标签:个数   i++   逆序对   color   nbsp   答案   多少   space   ace   

原文地址:http://www.cnblogs.com/JebediahKerman/p/6011273.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!