abyy a+poj1062

解决一个算法问题,目标是在遵循特定规则的情况下找到树木序列中美的最大总和。此问题涉及动态规划与数据结构操作。

A2. Oh Sweet Beaverette

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

— Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me?

— Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night?

At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcoming walk. He needed to cut down several trees.

Let's consider the woodland belt as a sequence of trees. Each tree i is described by the esthetic appeal ai — some trees are very esthetically pleasing, others are 'so-so', and some trees are positively ugly!

The Smart Beaver calculated that he needed the following effects to win the Beaverette's heart:

  • The first objective is to please the Beaverette: the sum of esthetic appeal of the remaining trees must be maximum possible;
  • the second objective is to surprise the Beaverette: the esthetic appeal of the first and the last trees in the resulting belt must be the same;
  • and of course, the walk should be successful: there must be at least two trees in the woodland belt left.

 

Now help the Smart Beaver! Which trees does he need to cut down to win the Beaverette's heart?

Input

The first line contains a single integer n — the initial number of trees in the woodland belt, 2 ≤ n. The second line contains space-separated integers ai — the esthetic appeals of each tree. All esthetic appeals do not exceed 109 in their absolute value.

 

  • to get 30 points, you need to solve the problem with constraints: n ≤ 100 (subproblem A1);
  • to get 100 points, you need to solve the problem with constraints: n ≤ 3·105 (subproblems A1+A2).

 

Output

In the first line print two integers — the total esthetic appeal of the woodland belt after the Smart Beaver's intervention and the number of the cut down trees k.

In the next line print k integers — the numbers of the trees the Beaver needs to cut down. Assume that the trees are numbered from 1 ton from left to right.

If there are multiple solutions, print any of them. It is guaranteed that at least two trees have equal esthetic appeal.

题意:有一排树,每个树有美丑值,让你砍出最大的一串,顺便要输出砍树的序号,砍树要求:

剩下的一串最左边和最右边相等,最少剩2棵树

其实这题跟最大子序列差不多,而且还不用按序列砍,随意砍的话我们用dp存到i为止最大能到多少,也就是dp[i]=dp[i-1]+a[i]>0?a[i]:0;

然后因为要头尾相等我们用map记录下每个新出的节点的序号,然后找对应的右端点与之对应,假如a[i]已经访问,就可以求他到左端的最大串,注意a[i]必须区,所以不能直接用dp[i]-dp[visit[a[i]-1],要是a[i]<0就跪了。

这题坑我的地方是,他0 0竟然不输出,我输出了0,就跪了,fuck

 

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
using namespace std;
struct node{
    int number;
    __int64 value;
};
int a[300010];
__int64 dp[300010];
int cut[300010];
node ans;
//__int64 ans[100010];
int main()
{
    map <int,int> visit;
    //__int64 sum;
    int i,j,m,n;
    //sum=0;
    int cnt=0;
    ans.value=-2000000010;
    memset(dp,0,sizeof(dp));
    cin>>n;
    for (i=1;i<=n;i++)
    cin>>a[i];
    for (i=1;i<=n;i++)
    {
            if (a[i]>=0)
            {
                dp[i]=dp[i-1]+a[i];
            }
            else {dp[i]=dp[i-1];}

        if (!visit[a[i]])      visit[a[i]]=i;
        else
        {
            if (ans.value<dp[i-1]-dp[visit[a[i]]]+2*a[i])
            {
                ans.value=dp[i-1]-dp[visit[a[i]]]+2*a[i];
                ans.number=i;
            }
        }
    }
        cout<<ans.value<<" ";
        for (i=1;i<visit[a[ans.number]];i++)
            cut[cnt++]=i;
        for (i=visit[a[ans.number]]+1;i<ans.number;i++)
            if (a[i]<0) cut[cnt++]=i;
        for (i=ans.number+1;i<=n;i++)
            cut[cnt++]=i;
        cout<<cnt<<endl;
        for (i=0;i<cnt-1;i++)
        cout<<cut[i]<<" ";
        if (cnt) cout<<cut[cnt-1]<<endl;
}


下面是poj1062,基本没什么好说的,模板题,我多加了分号,刚好空着一起写了

 

 

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#define inf 0x7fffffff
using namespace std;
bool visit[101];
int price[101][101],n;
int dist[102];
int djskl()
{
    int i,j,te;
    for (i=1;i<=n;i++)
    dist[i]=price[0][i];
    int node=0;
    for (j=1;j<=n;j++)
    {
        te=inf;
        for (i=1;i<=n;i++)
    {

        //cout<<dist[i]<<endl;
        if (te>dist[i]&&!visit[i])
        {
            te=dist[i];
            node=i;
            //cout<<te<<endl;
        }
    }
    if (node==0) break;
    //cout<<node<<endl;
    visit[node]=true;
    for (i=1;i<=n;i++)
    {
        if (!visit[i]&&price[node][i]>0&&dist[i]>dist[node]+price[node][i])
        dist[i]=dist[node]+price[node][i];
    }
    //cout<<node<<endl;
    }

    return dist[1];
}
int main()
{
    int level[101];
    int i,j,m,x,t,v;
    while (cin>>m>>n)
    {
        memset(price,0,sizeof(price));
        memset(visit,false,sizeof(visit));
        memset(level,0,sizeof(level));
        memset(dist,inf,sizeof(dist));
        for (i=1;i<=n;i++)
        {
            cin>>price[0][i]>>level[i]>>x;
            for (j=1;j<=x;j++)
            {
                cin>>t>>v;
                price[t][i]=v;
            }
        }
        //cout<<price[3][1]<<endl;
        v=inf;
        for (i=1;i<=n;i++)
        {
            for (j=1;j<=n;j++)
            {if (level[j]>level[i]||level[i]-level[j]>m)
            visit[j]=true;
            else visit[j]=false;}
            t=djskl();
            //cout<<dist[1]<<end
            //cout<<price[3][1]<<endl;
        if (t<v) v=t;

        }
        cout<<v<<endl;
        //cout<<price[4][1]<<endl;
        }
}


代码很差,没改的说。。。

 

 

【SCI一区复现】基于配电网韧性提升的应急移动电源预配置和动态调度(下)—MPS动态调度(Matlab代码实现)内容概要:本文档围绕“基于配电网韧性提升的应急移动电源预配置和动态调度”主题,重点介绍MPS(Mobile Power Sources)动态调度的Matlab代码实现,是SCI一区论文复现的技术资料。内容涵盖在灾害或故障等极端场景下,如何通过优化算法对应急移动电源进行科学调度,以提升配电网在突发事件中的恢复能力与供电可靠性。文档强调采用先进的智能优化算法进行建模求解,并结合IEEE标准测试系统(如IEEE33节点)进行仿真验证,具有较强的学术前沿性和工程应用价值。; 适合人群:具备电力系统基础知识和Matlab编程能力,从事电力系统优化、配电网韧性、应急电源调度等相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①用于复现高水平期刊(SCI一区、IEEE顶刊)中关于配电网韧性与移动电源调度的研究成果;②支撑科研项目中的模型构建与算法开发,提升配电网在故障后的快速恢复能力;③为电力系统应急调度策略提供仿真工具与技术参考。; 阅读建议:建议结合前篇“MPS预配置”内容系统学习,重点关注动态调度模型的数学建模、目标函数设计与Matlab代码实现细节,建议配合YALMIP等优化工具包进行仿真实验,并参考文中提供的网盘资源获取完整代码与数据。
一款AI短视频生成工具,只需输入一句产品卖点或内容主题,软件便能自动生成脚本、配音、字幕和特效,并在30秒内渲染出成片。 支持批量自动剪辑,能够实现无人值守的循环生产。 一键生成产品营销与泛内容短视频,AI批量自动剪辑,高颜值跨平台桌面端工具。 AI视频生成工具是一个桌面端应用,旨在通过AI技术简化短视频的制作流程。用户可以通过简单的提示词文本+视频分镜素材,快速且自动的剪辑出高质量的产品营销和泛内容短视频。该项目集成了AI驱动的文案生成、语音合成、视频剪辑、字幕特效等功能,旨在为用户提供开箱即用的短视频制作体验。 核心功能 AI驱动:集成了最新的AI技术,提升视频制作效率和质量 文案生成:基于提示词生成高质量的短视频文案 自动剪辑:支持多种视频格式,自动化批量处理视频剪辑任务 语音合成:将生成的文案转换为自然流畅的语音 字幕特效:自动添加字幕和特效,提升视频质量 批量处理:支持批量任务,按预设自动持续合成视频 多语言支持:支持中文、英文等多种语言,满足不同用户需求 开箱即用:无需复杂配置,用户可以快速上手 持续更新:定期发布新版本,修复bug并添加新功能 安全可靠:完全本地本地化运行,确保用户数据安全 用户友好:简洁直观的用户界面,易于操作 多平台支持:支持Windows、macOS和Linux等多个操作系统
源码来自:https://pan.quark.cn/s/2bb27108fef8 **MetaTrader 5的智能交易系统(EA)**MetaTrader 5(MT5)是由MetaQuotes Software Corp公司研发的一款广受欢迎的外汇交易及金融市场分析软件。 该平台具备高级图表、技术分析工具、自动化交易(借助EA,即Expert Advisor)以及算法交易等多项功能,使交易参与者能够高效且智能化地开展市场活动。 **抛物线SAR(Parabolic SAR)技术指标**抛物线SAR(Stop and Reverse)是由技术分析专家Wells Wilder所设计的一种趋势追踪工具,其目的在于识别价格走势的变动并设定止损及止盈界限。 SAR值的计算依赖于当前价格与前一个周期的SAR数值,随着价格的上扬或下滑,SAR会以一定的加速系数逐渐靠近价格轨迹,一旦价格走势发生逆转,SAR也会迅速调整方向,从而发出交易提示。 **Parabolic SAR EA的操作原理**在MetaTrader 5环境中,Parabolic SAR EA借助内嵌的iSAR工具来执行交易决策。 iSAR工具通过计算得出的SAR位置,辅助EA判断入市与离市机。 当市场价位触及SAR点,EA将产生开仓指令,倘若价格持续朝同一方向变动,SAR将同步移动,形成动态止损与止盈参考点。 当价格反向突破SAR,EA会结束当前仓位并可能建立反向仓位。 **智能交易系统(EA)的优越性**1. **自动化交易**:EA能够持续监控市场,依据既定策略自动完成买卖操作,减少人为情感对交易的影响。 2. **精确操作**:EA依照预设规则操作,无任何迟疑,从而提升交易成效。 3. **风险管控**:借助SA...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值