国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 绩溪县| 视频| 镇沅| 九寨沟县| 昭觉县| 叙永县| 乐安县| 云南省| 盱眙县| 胶南市| 中江县| 潮安县| 黔西县| 丰原市| 高雄市| 三明市| 阳城县| 行唐县| 合江县| 双城市| 洮南市| 越西县| 昌都县| 驻马店市| 灵丘县| 蒙山县| 丰原市| 宜兰县| 冀州市| 沙湾县| 镇宁| 库车县| 泗水县| 济宁市| 山丹县| 秀山| 仙游县| 钟山县| 银川市| 新民市| 珠海市|