1564. HOUSING
Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
Description
For the Youth Olympic Games in Singapore, the administration is considering to house each team in several units with at least 5 people per unit. A team can have from 5 to 100 members, depending on the sport they do. For example, if there are 16 team members, there are 6 ways to distribute the team members into units: (1) one unit with 16 team members; (2) two units with 5 and 11 team members, respectively; (3) two units with 6 and 10 team members, respectively; (4) two units with 7 and 9 team members, respectively; (5) two units with 8 team members each; (6) two units with 5 team members each plus a third unit with 6 team members. This list might become quite lengthy for a large team size.
In order to see how many choices to distribute the team members there are, the administration would like to have a computer program that computes for a number n the number m(n) of possible ways to distribute the team members into the units allocated, with at least 5 people per unit. Note that equivalent distributions like 5 + 5 + 6, 5 + 6 + 5 and 6 + 5 + 5 are counted only once. So m(16) = 6 (as seen above), m(17) = 7 (namely 17, 5 + 12, 6 + 11, 7 + 10, 8 + 9, 5 + 5 + 7, 5 + 6 + 6) and m(20) = 13.
The computer program should read the number n and compute m(n).
Input
The input contains just one number which is the number n as described above, where 5 <= n <= 100.
Output
The output consists of a single line with an integer that is the number m(n) as specified above. As n is at most 100, one can estimate that m(n) has at most 7 decimal digits.
Sample Input
20
Sample Output
13
dp[n][m]表示当前最少要用n来划分,m是剩下的人数。for i in range(n,m/2),dp[n][m]+=dp[i][m-i]。没有用记忆化搜索,因为数据量很小。下面是代码,蠢就蠢在学了新语言,忘记C里面的语法。
#include <bits/stdc++.h>
using namespace std;
int countt = 0;
//表示最少要用n,剩余m
void cal(int n,int m){
//血的教训 5<=m<10
if(5<=m&&m<10){
countt+=1;
if(m>=10){
for(int i=n;i<=m/2;i++)
cal(i,m-i);
countt+=1;
}
}
int main(){
int n;
while(~scanf("%d",&n)){
countt = 0;
cal(5,n);
printf("%d\n",countt);
}
}