zoukankan      html  css  js  c++  java
  • TJU 4087. box

    题目:Tuhao and his two small partners participated in the tournament.But in the end, they lost the chance to finish a mathematical problem.After the competition,Tuhao recalled that year in high school math class on a variety of tragedy.

    One day, the math teacher give Tuhao a question:if you have 5 boxes in a line(every boxes are different) and you have 4 kinds of balls.you must put an ball in every box, and all balls can take unlimited. How many kinds of way of placing? Tuhao solve this problem easily.But he has another question to you.if we have N boxes, and we have m kind of balls, and you can't use all kinds of balls because Tuhao must have one kind ball at least to play with his partners... 

    Input

    There will be multiple cases to consider. The first input will be a number T(0 < T ≤ 50) indicating how many cases with which you will deal. Following this number will be pairs of integers giving values for N and M, in that order. You are guaranteed that 1 ≤ N < 500, 1 ≤ M < 10, Each N M pair will occur on a line of its own. N and M will be separated by a single space.

    Output

    For each case display a line containing the case number (starting with 1 and increasing sequentially), and the kinds of way of placing. The desired format is illustrated in the sample shown below.(p.s. the answer should be module 200000007)

    Sample Input

    2 1 1 8 3 

    Sample Output

    Case 1: 0 Case 2: 765 
    一道推断题,每次拿到这样的题都手贱的去写方程表达式,结果越来越..

    解析:定义F[I][J]表示前I个格子用了J种颜色,有如下方程:

    F[I][J]=F[I-1][J-1]*(M-(J-1))+F[I-1][J]*J;

    F[I-1][J-1]*(M-(J-1)):加上一种新的颜色的方案数,(M-(J-1))是剩下没用的颜色数

    F[I-1][J]*J:从以前选了J种颜色中选一种、

     开始F[I][1]=M;我为了避免处理麻烦,从I=2时开始操作;

    代码要精简:^^;
    这是未加工的部分
            for (int i=1;i<=n;i++)
                    f[i][1]=1;
            for (int i=2;i<=n;i++)
                for (int j=1;j<=m;j++)
                f[i][j]=(f[i-1][j]*j+f[i-1][j-1]*(m-j+1))%maxn;

            int ans=0;
            for (int i=1;i<m;i++)
                ans=(ans+f[n][i])%maxn;
            printf("%d ",ans*m%maxn);
        }
        return 0;

    } 

  • 相关阅读:
    最简单的 Java内存模型 讲解
    Chrome快捷键吐血整理
    【并发编程】InheritableThreadLocal使用详解
    【并发编程】Object的wait、notify和notifyAll方法
    【并发编程】Thread类的详细介绍
    【软件工具】easyExcel简明使用指南
    【并发编程】实现多线程的几种方式
    【并发编程】Java并发编程传送门
    CODING 研发管理系统上线全球加速,助力企业跨区域协作
    上帝的归上帝,凯撒的归凯撒—— CODING 权限管理更新
  • 原文地址:https://www.cnblogs.com/forgot93/p/3806065.html
Copyright © 2011-2022 走看看