SGU 310. Hippopotamus (pressure DP)

Source: Internet
Author: User

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,Nm andk, separated by spaces and/or line breaks. 1≤N≤ 60, 1≤m≤ 15, 0≤kmN.

OutputOutput the number of possibilities.

Example (s)
Sample input
Sample output

Sample input
Sample output

Sample input
Sample output

SGU 310. Hippopotamus (pressure DP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.