SGU 310. Hippopotamus
310. Hippopotamus
Time limit per test: 0.5 second(s)
Memory limit: 65536 kilobytes
Memory limit: 65536 kilobytes
input: standard
output: standard
output: standard
After fixing your roof, you still think that it looks unpretty. So you opt for a new one, consisting of n consecutive long narrow boards. You have two types of boards: wooden ones and iron ones, giving you an amazing total of 2n possible roofs.
But the safety should not be left aside. Having considered the weight and the cruising speed of a falling hippopotamus, you decide to have at least k iron boards among every mconsecutive boards.
How many possibilities do you have?
Input
The input file contains three integers, n, m and k, separated by spaces and/or line breaks. 1 ≤ n ≤ 60, 1 ≤ m ≤ 15, 0 ≤ k ≤ m ≤ n.Output
Output the number of possibilities.Example(s)
sample input |
sample output |
10 2 1 |
144 |
sample input |
sample output |
5 5 2 |
26 |
sample input |
sample output |
3 2 2 |
1 |
Online Contester Team © 2002 - 2010. All rights reserved. |
水题,简单的DP
#include <iostream> #include<stdio.h> using namespace std; int a[50000]; long long b[70][50000]; int dog(int num) { int tot=0; while(num) { tot+=(num&1); num=(num>>1); } return tot; } int main() { int i,j,n,m,k; long long tot; for(i=0;i<(1<<15);i++) a[i]=dog(i); while(scanf("%d%d%d",&n,&m,&k)!=EOF) { for(i=1;i<=n;i++) for(j=0;j<(1<<m);j++) b[i][j]=0; for(i=0;i<(1<<m);i++) b[m][i]=(a[i]>=k?1:0); for(i=m+1;i<=n;i++) for(j=0;j<(1<<m);j++) { if (a[j]<k) continue; b[i][(j>>1)+(1<<(m-1))]+=b[i-1][j]; b[i][j>>1]+=b[i-1][j]; } tot=0; for(i=0;i<(1<<m);i++) if (a[i]>=k) tot+=b[n][i]; printf("%lld\n",tot); } return 0; }