国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

POJ2385-Apple Catching-簡(jiǎn)單dp

2019-11-08 18:25:46
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

原題鏈接 Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11850 Accepted: 5738 Description

It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his field, each full of apples. Bessie cannot reach the apples when they are on the tree, so she must wait for them to fall. However, she must catch them in the air since the apples bruise when they hit the ground (and no one wants to eat bruised apples). Bessie is a quick eater, so an apple she does catch is eaten in just a few seconds.

Each minute, one of the two apple trees drops an apple. Bessie, having much PRactice, can catch an apple if she is standing under a tree from which one falls. While Bessie can walk between the two trees quickly (in much less than a minute), she can stand under only one tree at any time. Moreover, cows do not get a lot of exercise, so she is not willing to walk back and forth between the trees endlessly (and thus misses some apples).

Apples fall (one each minute) for T (1 <= T <= 1,000) minutes. Bessie is willing to walk back and forth at most W (1 <= W <= 30) times. Given which tree will drop an apple each minute, determine the maximum number of apples which Bessie can catch. Bessie starts at tree 1. Input

Line 1: Two space separated integers: T and W

Lines 2..T+1: 1 or 2: the tree that will drop an apple each minute. Output

Line 1: The maximum number of apples Bessie can catch without walking more than W times. Sample Input

7 2 2 1 1 2 2 1 1 Sample Output

6 Hint

INPUT DETAILS:

Seven apples fall - one from tree 2, then two in a row from tree 1, then two in a row from tree 2, then two in a row from tree 1. Bessie is willing to walk from one tree to the other twice.

OUTPUT DETAILS:

Bessie can catch six apples by staying under tree 1 until the first two have dropped, then moving to tree 2 for the next two, then returning back to tree 1 for the final two. Source

USACO 2004 November

#include <cstdio>#include <iostream>using namespace std;int dp[35],loc[1010];int main(){ int T,n,x; cin >> T >> n; for(int i=1;i<=T;i++){ scanf("%d",&x); loc[i]=x%2; } for(int i=1;i<=T;i++){ dp[0]=dp[0] + !(((1+0)&1) ^ loc[i]); for(int j=1;j<=n;j++){ dp[j] = max(dp[j-1],dp[j]); dp[j] += !(((1+j)&1) ^ loc[i]); } } cout << dp[n] << endl;}
發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 西乌珠穆沁旗| 宜良县| 竹溪县| 重庆市| 巴彦淖尔市| 五指山市| 天水市| 宿州市| 天峨县| 玛多县| 嘉义县| 天祝| 绍兴县| 龙口市| 兴城市| 大安市| 兴安县| 县级市| 香港| 鹤山市| 谢通门县| 柳河县| 平邑县| 丁青县| 东乌珠穆沁旗| 灵山县| 历史| 通渭县| 盈江县| 栾城县| 迁安市| 三穗县| 景东| 宣化县| 龙海市| 拉孜县| 阿勒泰市| 武陟县| 武陟县| 当涂县| 茌平县|