title to the main idea: to the n block, there are a,b2 types of plates, require any m block continuous plate at least K Block B plate. 1≤n≤60,1≤m≤15,0≤k≤m≤n.
The DP (x, s) represents the X-plate, the state of the front M-block is s, and the legal state shifts.
---------------------------------------------------------------------------
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long Long ll; const int MAXN =;const int MAXM = +;#define B (x) (1 << (x))int N, M, K, Cnt[b (MAXM)];ll Dp[2][b (MAXM)];int main () {scanf ("%d%d%d", &n, &m, &k);int c = 0, p = 1;For (int s = B (M); s--;) {Cnt[s] = 0;for (int i = 0; i < M; i++)if (S & B (i)) cnt[s]++;Dp[c][s] = (Cnt[s] >= K);}int t = b (M-1);for (int i = n-m; i--;) {Swap (c, p);memset (Dp[c], 0, sizeof dp[c]);For (int s = B (M); s--;) if (Cnt[s >> 1] >= K) {dp[c][s >> 1] + = Dp[p][s];dp[c][s >> 1 | t] + = Dp[p][s];} else if (Cnt[s >> 1] + 1 = = K)dp[c][s >> 1 | t] + = Dp[p][s];}ll ans = 0;for (int i = B (M); i--;)if (Cnt[i] >= K) ans + = dp[c][i];printf ("%lld\n", ans);return 0;}
---------------------------------------------------------------------------
310. Hippopotamustime limit per test:0.5 second (s)
Memory limit:65536 Kilobytesinput:standard
Output:standard
After fixing your roof, you still think that it looks unpretty. So-you-opt for a new one, consisting of
Nconsecutive long narrow boards. You have both types of boards:wooden ones and iron ones, giving you a amazing total of 2
Npossible roofs.
But the safety should isn't being left aside. has considered the weight and the cruising speed of a falling hippopotamus, you decide to has at leastkIron boards among everymconsecutive boards.
How many possibilities does you have?
InputThe input file contains three integers,N, m andk, separated by spaces and/or line breaks. 1≤N≤ 60, 1≤m≤ 15, 0≤k≤m≤N.
OutputOutput the number of possibilities.
Example (s)
Sample input |
Sample output |
|
|
Sample input |
Sample output |
|
|
Sample input |
Sample output |
|
|
SGU 310. Hippopotamus (pressure DP)