Jumping Cows

Jumping Cows

时间限制(普通/Java):3000MS/10000MS          运行内存限制:65536KByte

描述

 

Farmer John's cows would like to jump over the moon, just like the cows in their favorite nursery rhyme. Unfortunately, cows can not jump.
The local witch doctor has mixed up P (1 <= P <= 150,000) potions to aid the cows in their quest to jump. These potions must be administered exactly in the order they were created, though some may be skipped.
Each potion has a 'strength' (1 <= strength <= 500) that enhances the cows' jumping ability. Taking a potion during an odd time step increases the cows' jump; taking a potion during an even time step decreases the jump. Before taking any potions the cows' jumping ability is, of course, 0.
No potion can be taken twice, and once the cow has begun taking potions, one potion must be taken during each time step, starting at time 1. One or more potions may be skipped in each turn.
Determine which potions to take to get the highest jump.

 

输入

* Line 1: A single integer, P
* Lines 2..P+1: Each line contains a single integer that is the strength of a potion. Line 2 gives the strength of the first potion; line 3 gives the strength of the second potion; and so on.

输出

* Line 1: A single integer that is the maximum possible jump.

样例输入

8
7
2
1
8
4
3
5
6

 

样例输出

17
 
题目大意:题目要求从输入的p个数中任意选出n(n<=p)个数按输入顺序排好,假设给n个数1至N编号,若i(1<=i<=N)是偶数,则将第i个数变为负数,最后求n个数的最大和。
 
#include<iostream>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<stdio.h>
using namespace std;

int main() {
    int n,i,j,x;
    int ans,sum;
    while(~scanf("%d",&n)) {
        scanf("%d",&x);
        ans = x;
        sum = 0;
        for(i=1; i<n; i++) {
            scanf("%d",&x);
            if(sum+x>ans)
                ans = sum+x;
            if(ans-x>sum)
                sum = ans-x;
        }
        if(ans>sum)
            printf("%d\n",ans);
        else
            printf("%d\n",sum);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/lavender913/p/3310851.html

Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to rock in a river. The excitement takes place on a long, straight river with a rock at the start and another rock at the end, L units away from the start (1 ≤ L ≤ 1,000,000,000). Along the river between the starting and ending rocks, N (0 ≤ N ≤ 50,000) more rocks appear, each at an integral distance Di from the start (0 < Di < L). To play the game, each cow in turn starts at the starting rock and tries to reach the finish at the ending rock, jumping only from rock to rock. Of course, less agile cows never make it to the final rock, ending up instead in the river. Farmer John is proud of his cows and watches this event each year. But as time goes by, he tires of watching the timid cows of the other farmers limp across the short distances between rocks placed too closely together. He plans to remove several rocks in order to increase the shortest distance a cow will have to jump to reach the end. He knows he cannot remove the starting and ending rocks, but he calculates that he has enough resources to remove up to M rocks (0 ≤ M ≤ N). FJ wants to know exactly how much he can increase the shortest distance *before* he starts removing the rocks. Help Farmer John determine the greatest possible shortest distance a cow has to jump after removing the optimal set of M rocks. Input Line 1: Three space-separated integers: L, N, and M Lines 2..N+1: Each line contains a single integer indicating how far some rock is away from the starting rock. No two rocks share the same position. Output Line 1: A single integer that is the maximum of the shortest distance a cow has to jump after removing M rocks Sample Inputcopy Outputcopy 25 5 2 2 14 11 21 17 4 Hint Before removing any rocks, the shortest jump was a jump of 2 from 0 (the start) to 2. After removing the rocks at 2 and 14, the shortest required jump is a jump of 4 (from 17 to 21 or from 21 to 25).
07-24
马尔科夫跳跃神经网络(Markovian Jumping Neural Networks, MJNNs)是一种结合了马尔科夫过程和人工神经网络的技术,常用于处理具有随机状态切换的数据,如时间序列预测和模式识别等。在MATLAB中,有许多库和工具箱可以支持MJNN的开发,如Neural Network Toolbox。 以下是一个简单的MATLAB代码示例,展示如何创建一个基本的马尔科夫跳跃神经网络模型: ```matlab % 导入所需库 addpath('toolbox/MJNetToolbox') % 假设MJNetToolbox已经安装 % 创建神经网络结构 numInputs = 10; % 输入特征数 hiddenNodes = [5, 3]; % 隐藏层节点数 numOutputs = 1; % 输出节点数 net = newMJNetwork(numInputs, hiddenNodes, numOutputs); % 设置马尔可夫转移矩阵和初始状态分布 T = randi([1, 3], 3, 3); % 生成一个3x3的随机马尔可夫矩阵,表示状态之间的概率转移 pi = ones(1, 3) / 3; % 初始状态均匀分布 % 训练网络 inputs = ... % 输入数据 targets = ... % 目标数据 net = train(net, inputs, targets, 'TransitionMatrix', T, 'InitialStateDistribution', pi); % 测试网络 testInputs = ... % 测试数据 outputs = predict(net, testInputs); ``` 请注意,这只是一个非常基础的框架,并未包括完整的训练循环和评估步骤。实际使用中,你需要提供适当的数据、调整网络参数并可能利用一些优化技术。此外,`newMJNetwork`, `train`, 和 `predict` 这些函数在真实环境中需要替换为对应的MJNetToolbox函数或自定义函数。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值