Bzoj 3384: [Usaco2004 nov]apple catching connect Apple (DP)

Source: Internet
Author: User

Dp

DP (x, k) = Max (DP (x-1, K-1) + * *, DP (X-1, k) + * * * = 0 or 1, as appropriate

(Bzoj 1750 double experience)

------------------------------------------------------------------------

#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#define REP (i, n) for (int i = 0; i < n; ++i)#define CLR (x, C) memset (x, C, sizeof (x))#define REP (i, n) for (int i = 1; I <= n; ++i)using namespace std;const INT MAXN = + 5;const INT MAXM = 5 +;int d[MAXN] [MAXM];int pos[MAXN];int n, t; int DP (int x, int k) {if (x < 1 | | k < 0) return 0;int &ans = d[x [k];if (ans! =-1) return ans;ans = 0;int p = 1 & k;//0, 1, 1, 2ans = max (DP (x-1, K) + (P = = pos[x]), DP (X-1, K-1) + (P! = pos[x]));return ans;}int main () {freopen ("test.in", "R", stdin);CLR (d,-1);cin >> n >> t;Rep (i, N)scanf ("%d", POS + i), pos[i]--;d[1] [0] =! pos[1];int ans = 0;Rep (i, T + 1) ans = max (DP (n, i), ans);cout << ans << "\ n";return 0;}

------------------------------------------------------------------------

3384: [Usaco2004 nov]apple catching pick up apple time limit: 1 Sec Memory Limit: MB
Submit: Solved: 18
[Submit] [Status] [Discuss] Descriptionfew people know that cows love apples. Farmer John has two apple trees on his farm (numbered 1 and 2), and each tree is covered with apples. Bessie could not pluck the apples from the tree, so she could only wait for the apples to fall from the trees. But as the apples fell to the ground, Bessie would have to catch the apples in midair (no one would like to eat the smashed apples). Bessie eats quickly, so she can finish it in just a few seconds after receiving the apple. Every minute, one of the two apple trees will drop an apple. Bessie had been trained enough to catch the apple falling from the tree as long as she stood under the tree. At the same time, Bessie was able to move quickly between two trees (moving for far less than 1 minutes), so when the apples fell, she would stand under one of the two trees. In addition, cows do not want to keep going between the two trees, so they miss some apples, the apples drop one per minute, a total of T (1≤t≤1000) minutes, and Bessie is willing to move the W (i≤w≤30) time. Now toThe number of trees that drop apples per minute, asking for the maximum number of apples that Bessie can catch. At first, Bessie was under tree 1th. Inputline 1th: two integers t and W separated by a space.2nd to t+1:1 or 2 (the number of trees that drop apples per minute). OutputThe maximum number of apples she can receive if Bessie does not move more than WSample Input9 |
2
1
1
2
2
1
1Sample Output6HINT

Drop 7 apples in 7 minutes one by one the 1 are dropped from the 2 tree , the next 2 apples fall from the 1 tree, and then the next 2 are from the second 2 trees fall, and the last 2 fall from the first 1 trees. Bessie does not move until it receives two apples that fall from the 1 tree, and then moves to the 2 tree until it receives a tree from the first 2


the two apples dropped on the tree and finally moved under the 1 tree to catch the last two apples falling from the 1 tree. So Bessie caught 6 apples altogether.


Source

Gold

Bzoj 3384: [Usaco2004 nov]apple catching connect Apple (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.