Cf273 (D2) d DP

Source: Internet
Author: User

[Question ]:

Given n green bricks and M red bricks, build as high as possible, each line can only use one color.

How many heap methods are available.

[Knowledge point ]:

DP scrolling Array

[Question ]:

In the code, DP [I] indicates the type of accumulation corresponding to the I red block.

    REP(i, h)        for(int j = N - i; j >= 0; j--)            dp[i + j] = (dp[i + j] + dp[j]) % MOD;

The first layer of the cycle indicates that the length of the building blocks is increased from small to large, and the second layer is updated in a rolling manner.

[Code ]:

#include <map>#include <set>#include <cmath>#include <ctime>#include <queue>#include <stack>#include <cstdio>#include <string>#include <vector>#include <cstring>#include <sstream>#include <iostream>#include <algorithm>#include <bitset>#include <climits>using namespace std;#define wh while#define inf (int)(~0u/2)#define FOR(i, n) for(int i = 0; i < n; i++)#define FOR1(i, n) for(int i = 1; i < n; i++)#define FOR2(i, n) for(int i = 0; i <= n; i++)#define REP(i,n) for(int i = 1; i <= n; i++)#define FORI(it,n) for(typeof(n.begin()) it = n.begin(); it != n.end(); it++)#define sf scanf#define pf printf#define frs first#define sec second#define psh push_back#define mkp make_pair#define PB(x) push_back(x)#define MP(x, y) make_pair(x, y)#define clr(abc,z) memset(abc,z,sizeof(abc))#define lt(v) v << 1#define rt(v) v << 1 | 1//#define mid ((l + r) >> 1)#define lson l, mid, v << 1#define rson mid + 1, r, v << 1 | 1#define fre freopen("1.txt", "r", stdin)typedef long long LL;typedef long double LD;int N, M;const int maxn = 2e5 + 100;const int MOD = 1000000007;int dp[maxn];int main() {    sf("%d%d", &N, &M);    int h; for(h = 1; h * (h + 1) / 2 <= (N + M); h++); h--;    dp[0] = 1;    REP(i, h)        for(int j = N - i; j >= 0; j--)            dp[i + j] = (dp[i + j] + dp[j]) % MOD;    h = (h + 1) * h / 2; int ans; ans = 0;    for(int j = 0; j <= N; j++)        if(h - j <= M) ans = (ans + dp[j]) % MOD;    pf("%d\n", ans);}

 

Cf273 (D2) d 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.