点击这里更换您喜欢的皮肤wtboj 首页
请点击这里登入noios   首页 入门 c++讲义 入门教程视频 其他页面 入门视频 站务 公告 | 题库 记录 竞测 测试 闯关 作业 排名 团队 讨论 | 换肤 | 登入 注册  
News >>   新增功能:各团队管理员可以发布本团队作业了 ()

From VijosGuest0
分球
讨论 Discussion
 
题目都看不懂!
背景 Background
为了for beginngers,特设此题,^_^
描述 Description
分球
有n个标号的球分到m个无差别的盒子里,每个盒子至少有一个球,问方案

数。
输入
多组数据;
每部分1行两个数n和m
输出
每组1行1个数,表示方案数。
样例
输入(ball.in):
4 2
1 1
输出(ball.out):
7
1
样例解释
n=4,m=2
1,2 3 4
2,1 3 4
3,1 2 4
4,1 2 3
1 2,3 4
1 3,2 4
1 4,2 3
数据规模
20%,满足1=<n,m<=10
100%,满足1=<n,m<=100,数据组数<=10

输入格式 Input Format
多组数据;
每部分1行两个数n和m
输出格式 Output Format
每组1行1个数,表示方案数。
样例输入 Sample Input

4 2
1 1
样例输出 Sample Output

7
1
时间限制 Time Limitation
各个测试点1s

( )

分球
#include <iostream>  
#include <cstdio>  
#include <cstdlib>
#include <cstring>  
using namespace std;  
struct gx{
int len;
short y[201];
}g[101];  
gx cheng(gx t,int s){
int i,k;
for( i=1;i<=t.len;i++)t.y[i]*=s;
for(i=1;i<=t.len;i++){
t.y[i+1]+= t.y[i]/10;
t.y[i]%=10;
}
k=t.len+1;
while(t.y[k]>10){
t.y[k+1]+=t.y[k]/10;
t.y[k]%=10;
k++;
};
while(t.y[k]==0)k--;
t.len=k;
return t;

}
gx jia(gx a,gx b){//高精度数a+b
int i,j,k; gx c;
c.len=0;
memset(&c,0,sizeof(struct gx));
k=(a.len>b.len)?a.len:b.len;
for(i=1;i<=k;i++){
c.y[i]+=a.y[i]+b.y[i];
if (c.y[i]>=10){
c.y[i+1]+=(c.y[i]/10);
c.y[i]%=10;
}

}
k++;
while( c.y[k]==0)k--;
c.len=k;
return c;

}
int main()  
{  
freopen("p1088.in","r",stdin);
freopen("p1088.out","w",stdout);
int n,m;  
int i,j;  
while(!feof(stdin)){
n=0;m=0;
cin >> n >> m;  
if(m==0&&n==0)break;
if(n<m){
cout<<0<<endl;
continue;
}
memset(&g,0,sizeof(struct gx)*101);
g[1].len=1;g[1].y[1]=1;//
for(i=1;i<=n;i++)  
{  
for(j=m;j>=1;j--)
{  
if (i<j)  
{  
memset(&g[j],0,sizeof(struct gx));
continue;  
}  
g[j]=jia(cheng(g[j],j),g[j-1]);
}  
}  
for(i=g[m].len;i>=1;i--)cout<<g[m].y[i];
cout<<endl;
}
fclose(stdin);
fclose(stdout);
return 0;  
}  
( )
发布讨论主题 回复讨论主题
Flag
  
题号
  P1088
  其它
通过
  31人
提交
  105次
通过率
  30%
难度
  2
提交 讨论 题解
 Copyright wtboj © 2005-2006. www.wutuobang.date Powered by wtboj 关于 联系 帮助
 wtboj Information ---- Total Users : 1368 | Online Users / Processes : 0 / 202 | Processed Time : 1031 ms | Server Time : 2026/3/15 22:49:52