2017湖南多校第二场-20170312

F(1833): Lab
Submit Status Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 35 Solved: 12
Description
Susan, your friend, is working in a biology lab. She is working in a very strict lab and she wants her boss to see her at work in the lab. However, doing experiments is very draining, so for every day she spends in the lab she needs at least two days away to recover, e.g. if she runs her experiment on Monday, the next soonest day for her next experiment is Thursday of the same week. Based on the visiting history, given n days, she knows the probability, P = {p1, p2, …, pn}, where pi is the probability that her boss will visit the lab on the ith day. She asks you to help her find the best schedule that she should perform her experiments to maximize the total sum of the probability based on the given history. Susan can perform her experiment on as many days as she wishes so long as she rests in between.

Input
The first line of input contains a single number, T, the number of test case. 0 < T <= 20. For each test case, it has two lines. The first line is a single number, n, the number of days you have the history. The second line contains n numbers, the probability of her advisor visiting on each day from day 1 to day n, 0 < n <= 1000. For each projection, the number is between 0 and 1. The probability values are double value and separated by a single space.

Output
For each test case, output a single number the maximum probability that can be gained based on the given projection. The number should be rounded to the nearest one decimal point. For the case of x.x5, we accept all methods of rounding.

Sample Input
2
5
0.2 0.11 0.5 1.0 0.0
9
0.0 0.2 0.12 0.4 0.01 0.9 0.9 0.8 1.0
Sample Output
1.2
2.1

动态规划

#include<bits/stdc++.h>
using namespace std;
double a[1005],dp[1005];

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        dp[0]=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%lf",&a[i]);
            dp[i]=max(dp[i-1],a[i]);
            if(i-3>0)
                dp[i]=max(dp[i],dp[i-3]+a[i]);
        }
        printf("%.1lf\n",dp[n]);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值