zoukankan      html  css  js  c++  java
  • HDU 2512 一卡通大冒险(dp)

    一卡通大冒险

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 2137    Accepted Submission(s): 1430


    Problem Description
    因为长期钻研算法, 无暇顾及个人问题,BUAA ACM/ICPC 训练小组的帅哥们大部分都是单身。某天,他们在机房商量一个绝妙的计划"一卡通大冒险"。这个计划是由wf最先提出来的,计划的内容是,把自己的联系方式写在校园一卡通的背面,然后故意将自己的卡"遗失"在某处(如水房,TD,食堂,主M。。。。)他们希望能有MM看到他们遗失卡,能主动跟他们联系,这样就有机会请MM吃饭了。他们决定将自己的一卡通夹在基本相同的书里,然后再将书遗失到校园的各个角落。正当大家为这个绝妙的计划叫好时,大家想到一个问题。很明显,如果只有一张一卡通,那么只有一种方法,即,将其夹入一本书中。当有两张一卡通时,就有了两种选择,即,将两张一卡通夹在一本书里,或者分开夹在不同的书里。当有三张一卡通时,他们就有了5种选择,即:
    {{A},{B},{C}} , {{A,B},{C}}, {{B,C},{A}}, {{A,C},{B}} ,{{A,B,C}} 于是,
    这个邪恶计划的组织者wf希望了解,如果ACM训练对里有n位帅哥(即有N张一卡通),那么要把这些一卡通夹到书里有多少种不同的方法。
     
    Input
    包含多组数据,第一行为n,表示接下来有n组数据。以下每行一个数x,表示共有x张一卡通。(1≤x≤2000).
     
    Output
    对每组数据,输出一行:不同的方法数,因为这个数可能非常大,我们只需要它除以1000的余数。
     
    Sample Input
    4 1 2 3 100
     
    Sample Output
    1 2 5 751
     
    Author
    BUAA Campus 2007

    dp[i][j]代表前i个卡,分成j组的方法数。

    当新添加一张卡时,可以选则单独放这张卡那么此时有dp[i-1][j-1]种方法。也可以选择把这张卡插入到原来的分组中,即前i-1个数分成j组后再把第i张卡片插入。有dp[i-1][j]*j种方法。

    /* ***********************************************
    Author        :guanjun
    Created Time  :2016/6/12 20:31:58
    File Name     :hdu2512.cpp
    ************************************************ */
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <stdio.h>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    #include <list>
    #include <deque>
    #include <stack>
    #define ull unsigned long long
    #define ll long long
    #define mod 1000
    #define INF 0x3f3f3f3f
    #define maxn 10000
    #define cle(a) memset(a,0,sizeof(a))
    const ull inf = 1LL << 61;
    const double eps=1e-5;
    using namespace std;
    priority_queue<int,vector<int>,greater<int> >pq;
    struct Node{
        int x,y;
    };
    struct cmp{
        bool operator()(Node a,Node b){
            if(a.x==b.x) return a.y> b.y;
            return a.x>b.x;
        }
    };
    
    bool cmp(int a,int b){
        return a>b;
    }
    int dp[2010][2010];
    int n;
    int main()
    {
        #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        #endif
        //freopen("out.txt","w",stdout);
        int t;
        cin>>t;
        while(t--){
            scanf("%d",&n);
            cle(dp);
            dp[0][0]=1;
            for(int i=1;i<=n;i++){
                for(int j=1;j<=i;j++){
                    dp[i][j]=dp[i-1][j-1]+dp[i-1][j]*j;
                    dp[i][j]%=mod;
                }
            }
            int ans=0;
            for(int i=1;i<=n;i++)
                ans+=dp[n][i];
            cout<<ans%mod<<endl;
        }
        return 0;
    }
  • 相关阅读:
    怎样提高开发效率
    ASP.NET/C#获取文章中图片的地址
    listBox的用法
    ASP.NET中的asp:label和asp:literal
    ID,ClientID,UniqueID的区别
    asp.net中的属性
    数据库中的值为空的判断 ,并赋初值
    属性器,转换从数据库中读取的状态
    Collections.emptyList() and Collections.EMPTY_LIST
    InnoDB
  • 原文地址:https://www.cnblogs.com/pk28/p/5578821.html
Copyright © 2011-2022 走看看