• nyoj 451 光棍节的快乐


    View Code
     1  
     2 /*********************************
     3 /   Problem:
     4 /   Algorithm:
     5 /   Language:   C++
     6 /   Compiler:   MinGW
     7 /   Date:       12/08/010
     8 /
     9 /   Copyright (C) wujianwei
    10 /   All rights reserved.
    11 ********************************/
    12 
    13 #include <iostream>
    14 #include <cstdio>
    15 #include <cstring>
    16 #include <cmath>
    17 #include <vector>
    18 #include <cstring>
    19 #include <queue>
    20 #include <stack>
    21 #include <algorithm>
    22 #include <set>
    23 
    24 using namespace std;
    25 
    26 #define INF 0x7fffffff
    27 #define EPS 1e-12
    28 #define MOD 1000000007
    29 #define PI 3.141592653579798
    30 #define N 100000
    31 const int MAX=1<<28;
    32 typedef long long LL;
    33 //typedef __int64 INT
    34 
    35 LL a[21]={1,1};
    36 
    37 void row()
    38 {
    39     LL i,j;
    40     for(i=2;i<=20;i++)
    41     {
    42         a[i]=a[i-1]*i;
    43     }
    44 }
    45 
    46 LL row2(int n,int m)
    47 {
    48     return (a[n]/a[n-m])/a[m];
    49 }
    50 
    51 int main()
    52 {
    53     LL n,m;
    54     row();
    55     while(~scanf("%lld%lld",&n,&m))
    56     {
    57         LL sum=a[m];
    58         for(int i=1;i<=m;i++)
    59         {
    60             int b=1;
    61             if(i&1) b=-1;
    62             sum+=b*a[m]/a[i];
    63         }
    64     sum*=row2(n,m);
    65     printf("%lld\n",sum);
    66     }
    67     return 0;
    68 }
    69         

     

    光棍节的快乐

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:2
     
    描述

    光棍们,今天是光棍节。聪明的NS想到了一个活动来丰富这个光棍节。

    规则如下:

    每个光棍在一个纸条上写一个自己心仪女生的名字,然后把这些纸条装进一个盒子里,这些光 棍依次抽取一张纸条,如果上面的名字就是自己心仪的女生,那么主持人就在现场给该女生打电话,告诉这个光棍对她的爱慕之情,并让光棍当场表白,并得到现场所有人的祝福,没抽到的,嘿嘿就可以幸免了。

    假设一共有N个光棍,其中有M个没有抽到自己的纸条,求发生这种情况一共有多少种可能.。

     
    输入
    每行包含两个整数N和M(1<M<=N<=20),以EOF结尾。
    输出
    对于每个测试实例,请输出一共有多少种发生这种情况的可能,每个实例的输出占一行。
    样例输入
    2 2
    3 2
    样例输出
    1
    3
    上传者
    林海雪原
     
    错位排列的应用
    其实错位排列还可以用 a[n]=(n-1)(a[n-1]+a[n-2])
    我用的方法不提倡
    但是用于求排列挺好的
  • 相关阅读:
    scrapy通过修改配置文件发送状态邮件
    python高级编程读书笔记(一)
    linux,mac安装sentry
    mac安装sentry
    pop3设置
    流程图
    车险或将二次费改 又可以省钱了?
    ATM:模拟实现一个ATM + 购物商城程序
    作业1开发一个简单的python计算器
    re正则表达式
  • 原文地址:https://www.cnblogs.com/wujianwei/p/2637058.html
Copyright © 2020-2023  润新知