码迷,mamicode.com
首页 > 其他好文 > 详细

HDOJ题目2861 Stools(递推)

时间:2015-05-22 09:49:15      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

Stools

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 626    Accepted Submission(s): 227


Problem Description
Patti and Terri run a bar in which there are 15 stools. One day, Darrell entered the bar and found that the situation how customers chose the stools were as follows:
OOEOOOOEEEOOOEO
O means that the stool in a certain position is used, while E means that the stool in a certain position is empty (here what we care is not who sits on the stool, but whether the stool is empty).As the example we show above, we can say the situation how the 15 stools is used determines 7 intervals (as following):
OO E OOOO EEE OOO E O

Now we postulate that there are N stools and M customers, which make up K intervals. How many arrangements do you think will satisfy the condition?
 

Input
There are multi test cases and for each test case:
Each case contains three integers N (0<N<=200), M (M<=N), K (K<=20).
 

Output
For each test case print the number of arrangements as described above. (All answers is fit in 64-bit.)
 

Sample Input
3 1 3 4 2 4
 

Sample Output
1 2
 

Source
 

Recommend
gaojie   |   We have carefully selected several similar problems for you:  2858 2860 2859 2856 2854 
 

a[n][m][k]=a[n-1][m][k]+b[n-1][m][k-1];
    b[n][m][k]=a[n-1][m-1][k-1]+b[n-1][m-1][k];
    ans[n][m][k]=a[n][m][k]+b[n][m][k]。

    a[n][m][k]:n个座位、m个人、k段、最后一个位置么有人,的情况数;

    b[n][m][k]:n个座位、m个人、k段、最后一个位置有人,的情况数。

ac代码

#include<stdio.h>
#include<string.h>
__int64 a[220][220][22],b[220][220][22];
void init()
{
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	a[1][0][1]=1;
	b[1][1][1]=1;
	int i,j,k;
	for(i=2;i<=200;i++)
	{
		for(j=0;j<=i;j++)
		{
			for(k=1;k<=i&&k<22;k++)
			{
				a[i][j][k]=a[i-1][j][k]+b[i-1][j][k-1];
				if(j)
					b[i][j][k]=a[i-1][j-1][k-1]+b[i-1][j-1][k];
			}
		}
	}
}
int main()
{
	init();
	int n,m,k;
	while(scanf("%d%d%d",&n,&m,&k)!=EOF)
	{
		printf("%I64d\n",a[n][m][k]+b[n][m][k]);
	}
}


HDOJ题目2861 Stools(递推)

标签:

原文地址:http://blog.csdn.net/yu_ch_sh/article/details/45897387

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!