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=;i<=n;i++)
f[i][]=;
for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
f[i][j]=(f[i-][j]*j+f[i-][j-]*(m-j+))%maxn; int ans=;
for (int i=;i<m;i++)
ans=(ans+f[n][i])%maxn;
printf("%d\n",ans*m%maxn);
}
return ;
}
TJU 4087. box的更多相关文章
- BOX
题目连接:http://acm.tju.edu.cn/toj/showp2392.html2392. Box Time Limit: 1.0 Seconds Memory Limit: 655 ...
- Virtual Box配置CentOS7网络(图文教程)
之前很多次安装CentOS7虚拟机,每次配置网络在网上找教程,今天总结一下,全图文配置,方便以后查看. Virtual Box可选的网络接入方式包括: NAT 网络地址转换模式(NAT,Network ...
- Linux监控工具介绍系列——OSWatcher Black Box
OSWatcher Balck Box简介 OSWatcher Black Box (oswbb)是Oracle开发.提供的一个小巧,但是实用.强大的系统工具,它可以用来抓取操作系统的性能指标,用 ...
- 使用packer制作vagrant centos box
使用packer制作vagrant box:centos 制作vagrant box,网上有教程,可以自己step by step的操作.不过直接使用虚拟在VirtualBox中制作vagrant b ...
- 快速打造跨平台开发环境 vagrant + virtualbox + box
工欲善其事必先利其器,开发环境 和 开发工具 就是 我们开发人员的剑,所以我们需要一个快并且好用的剑 刚开始做开发的时候的都是把开发环境 配置在 自己的电脑上,随着后面我们接触的东西越来越多,慢慢的电 ...
- CSS3伸缩盒Flexible Box
这是一种全新的布局,在移动端非常实用,IE对此布局的相关的兼容不是很好,Firefox.Chrome.Safrai等需要加浏览器前缀. 先说说这种布局的特点: 1)移动端由于屏幕宽度都不一样,在布局的 ...
- CSS3与页面布局学习总结(二)——Box Model、边距折叠、内联与块标签、CSSReset
一.盒子模型(Box Model) 盒子模型也有人称为框模型,HTML中的多数元素都会在浏览器中生成一个矩形的区域,每个区域包含四个组成部分,从外向内依次是:外边距(Margin).边框(Border ...
- 解析opencv中Box Filter的实现并提出进一步加速的方案(源码共享)。
说明:本文所有算法的涉及到的优化均指在PC上进行的,对于其他构架是否合适未知,请自行试验. Box Filter,最经典的一种领域操作,在无数的场合中都有着广泛的应用,作为一个很基础的函数,其性能的好 ...
- HDOJ 1326. Box of Bricks 纯水题
Box of Bricks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
随机推荐
- lua进阶(二)
第五章 函数 函数有两种用途:1.完成指定的任务,这种情况下函数作为调用语句使用:2.计算并 返回值,这种情况下函数作为赋值语句的表达式使用. function function_name( . ...
- xml结构
一.XmlHelper using System; using System.Collections.Generic; using System.Linq; using System.Web; usi ...
- 图表控件MsChart使用demo
chart 控件主要有 Titles 标题集合 Chart Area图形显示区域 Series图表集合 Legends图列的集合 (1) 常用事件: 1. Series1.Points.DataB ...
- C# 标准查询表达式
一.标准查询运算符 1.C#提供了标准查询运算符,例如我想选择专利一系列(pantents)中以年份19开头的专利,可以用如下语句: IEnumerable<Patent> pantent ...
- MVC中的奇葩错误,参数转对象
在使用MVC中遇到一个神奇的错误,特此记录(我在用MVC4时遇到) 上面两张图就是一个变量名进行了修改,其他不变!form里面的参数也是一样的!喜欢尝试的可以尝试一下! 我的变量使用action时出现 ...
- iOS学习之C语言结构体
结构体:用来存放相同类型数据或者不同类型数据的自定义类型. 结构体定义(声明) struct 结构体名 { 成员变量1; 成员变量2; ... }; typedef 现有类型 新的类 ...
- 基于xmpp openfire smack开发之Android客户端开发[3]
在上两篇文章中,我们依次介绍openfire部署以及smack常用API的使用,这一节中我们着力介绍如何基于asmack开发一个Android的客户端,本篇的重点在实践,讲解和原理环节,大家可以参考前 ...
- swift someObject == nil 如何实现
以前的编程经验告诉我们判断一个对象是否为空或者是否实例化可以这样 if(someObject == nil){ //do something }else{ } 但是在Swift中这样是不行的,然后我在 ...
- 利用LibreOffice转换ppt、doc转化pdf
利用LibreOffice转换ppt.doc转化pdf LibreOffice下载地址: http://www.libreoffice.org/download/libreoffice-fresh/ ...
- ASP运行流程(主要的类笔记)
个人笔记:参考汤姆大叔的MVC之前那些事系列整理 client端发送页面请求,被IIS的某个进程截获,它根据申请的页面后缀(.aspx)不同,调用不同的页面处理程序(.asp->asp.dll ...