NEFU642:monkey(DP)
2017-04-02 17:42
363 查看
monkey
Problem:642
Time Limit:1000ms
Memory Limit:65536K
Description
Cc is a lovely monkey. It likes to play the game "catching plates". The game is as follows. There are n pegs in a line numbered from 1 to n. Cc stands on the first peg at the beginning. It is rather hard for Cc to jump from peg i to peg i+1(i+1<=n) or peg i-1(i-1>=1), which takes him exactly one second. He can jump at most t times. And he will only jump at the beginning of one second.There is a clown at the other end. He has m plates in hand. He will throw a plate to one peg every second. The clown will throw the plate exactly to the peg. The plates will get broken if they hit the pegs. Cc can catch the plate if only he stands on the peg the plate is thrown to. For simplicity, the process of throwing and catching don't take any time at all. Suppose the clown will throw a plate to the 9th peg at the 9th second, if Cc stands on peg 9 at the 8th second and stands still for a second, or if Cc stand on peg 8 at the 8th second and jumps to peg 9, or if Cc stand on peg 10 at the 8th second and jumps to peg 9, he can catch the plate. There is a positive integer on each plate, indicating the bananas Cc can get if he catch that plate. Cc will know the way the clown throw the plates in advance. Now he wants to get as many bananas as possible.
Input
For each test case,the first line contains three integers n, m and t(1 <= n <= 100,1 <= m <= 100,0 <= t <= 100), indicating the number of the pegs, the number of the plates and the maximum number Cc can jump.The next m lines gives ai and bi each, which means the clown will throw a plate with number bi on it to peg ai at the ith second. Process to the end of file.
Output
For each test case, first print a line saying "Scenario #k", where k is the number of the test case.Then, print the maximum number Cc can get, one per line.Print a blank line after each test case, even after the last one.
Sample Input
4 4 2 2 10 3 15 1 10 1 8 4 4 4 2 10 3 15 1 10 1 8 2 2 1 1 1 2 1
Sample Output
Scenario #1 28 Scenario #2 33 Scenario #3 2
Hint
Source
题意:n个点,m个事件,t为移动次数上限,主角初始在1号点,每次可以向前或向后移动1格或者不移动,下面1~m行给出每秒在某个点出现一个碟子,每个碟子有一个分数,问不超过t次移动,主角能获得的最大分数。思路:dp[i][j][k]表示在i秒时在j位置体力为k获得的最大分数,三次循环就可以了。# include <iostream># include <cstdio># include <cstring># include <algorithm>using namespace std;int dp[103][103][103];int a[103][103];int main(){int n, m, b, c, t,cas=1;while(~scanf("%d%d%d",&n,&m,&t)){memset(a, 0, sizeof(a));memset(dp, -1, sizeof(dp));memset(a, 0, sizeof(a));dp[0][1][0] = 0;for(int i=1; i<=m; ++i){scanf("%d%d",&b,&c);a[i][b] = c;}int imax = 0;for(int i=1; i<=m; ++i){for(int j=1; j<=n; ++j){if(j == 1 && dp[i-1][j][0] != -1){dp[i][j][0] = dp[i-1][j][0] + a[i][j];imax = max(imax, dp[i][j][0]);}for(int k=1; k<=t; ++k){for(int l=j-1; l<=j+1; ++l){if(dp[i-1][l][l==j?k:k-1] == -1) continue;dp[i][j][k] = max(dp[i][j][k], dp[i-1][l][l==j?k:k-1]+a[i][j]);imax = max(imax, dp[i][j][k]);}}}}printf("Scenario #%d\n%d\n\n",cas++,imax);}return 0;}相关文章推荐
- NEFU 642 monkey(DP+优化)
- NEFU 642 monkey(DP+优化)
- NEFU 642 Monkey(DP)
- NEFU 642 monkey
- nefu 642 monkey
- NEFU 642 monkey(记忆化搜索)
- NEFU 642 monkey 记忆化搜索
- NEFU 642 monkey 记忆化搜索
- nefu 394 素数价值(dp或规律)
- HDU-1069 Monkey and Banana (DP)
- HDU 1069 Monkey and Banana(dp)
- hdu 1069 Monkey and Banana (DP)
- [HDU 1069]Monkey and Banana(DP)
- hdu 3689 杭州 10 现场 J - Infinite monkey theorem 概率dp kmp 难度:1
- hdoj--1069 Monkey and Banana(dp)
- hdu Monkey and Banana(DP)
- HDU 1069 Monkey and Banana (经典dp)详解及易错点分析
- LightOJ 1004 - Monkey Banana Problem 【DP】
- NEFU 641 素数树(树形DP)
- [HDOJ1069]Monkey and Banana(DP)