uva 590 Always on the run 跑路

本文介绍了一种基于动态规划的方法来解决一个特定的问题——如何在有限预算下,通过选择最佳航班组合来完成一系列城市间的逃逸。问题设定在一个有趣的故事背景下,即一个艺术大盗试图躲避警方追捕的同时,还需考虑航班价格波动及航线可用性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原题:
Always on the run

Screeching tires. Searching lights. Wailing sirens. Police cars everywhere. Trisha Quickfinger did it again! Stealing the `Mona Lisa’ had been more difficult than planned, but being the world’s best art thief means expecting the unexpected. So here she is, the wrapped frame tucked firmly under her arm, running to catch the northbound metro to Charles-de-Gaulle airport.

But even more important than actually stealing the painting is to shake off the police that will soon be following her. Trisha’s plan is simple: for several days she will be flying from one city to another, making one flight per day. When she is reasonably sure that the police has lost her trail, she will fly to Atlanta and meet her `customer’ (known only as Mr. P.) to deliver the painting.

Her plan is complicated by the fact that nowadays, even when you are stealing expensive art, you have to watch your spending budget. Trisha therefore wants to spend the least money possible on her escape flights. This is not easy, since airlines prices and flight availability vary from day to day. The price and availability of an airline connection depends on the two cities involved and the day of travel. Every pair of cities has a `flight schedule’ which repeats every few days. The length of the period may be different for each pair of cities and for each direction.

Although Trisha is a good at stealing paintings, she easily gets confused when booking airline flights. This is where you come in.

Input
The input file contains the descriptions of several scenarios in which Trisha tries to escape. Every description starts with a line containing two integers n and k. n is the number of cities through which Trisha’s escape may take her, and k is the number of flights she will take. The cities are numbered 1,2,,n, where 1 is Paris, her starting point, and n is Atlanta, her final destination. The numbers will satisfy 2ŸnŸ10 and 1ŸkŸ1000.

Next you are given n(n - 1) flight schedules, one per line, describing the connection between every possible pair of cities. The first n - 1 flight schedules correspond to the flights from city 1 to all other cities ( 2,3,,n), the next n - 1 lines to those from city 2 to all others ( 1,3,4,,n), and so on.

The description of the flight schedule itself starts with an integer d, the length of the period in days, with 1ŸdŸ30. Following this are d non-negative integers, representing the cost of the flight between the two cities on days 1,2,,d. A cost of 0 means that there is no flight between the two cities on that day.

So, for example, the flight schedule “3 75 0 80” means that on the first day the flight costs 75, on the second day there is no flight, on the third day it costs 80, and then the cycle repeats: on the fourth day the flight costs 75, there is no flight on the fifth day, etc.

The input is terminated by a scenario having n = k = 0.

Output
For each scenario in the input, first output the number of the scenario, as shown in the sample output. If it is possible for Trisha to travel k days, starting in city 1, each day flying to a different city than the day before, and finally (after k days) arriving in city n, then print “The best flight costs x.”, where x is the least amount that the k flights can cost.

If it is not possible to travel in such a way, print “No flight possible.”.

Print a blank line after each scenario.

Sample Input

3 6
2 130 150
3 75 0 80
7 120 110 0 100 110 120 0
4 60 70 60 50
3 0 135 140
2 70 80
2 3
2 0 70
1 80
0 0

Sample Output

Scenario #1
The best flight costs 460.

Scenario #2
No flight possible.
题目大意:
故事挺容易读明白,但是操作过程我读的比较费劲。首先给出两个数n,和k分别表示有n个国家和要和警察周旋的天数。然后行n*(n-1),每行分别表示第i个国家到第j个国家的航班。如样例1中,其中i到j的排列顺序是1->2, 1->3,2->1, 2->3, 3->1 ,3->2,每行先给出一个数d表示在第i个国家到第j个国家的花销。其中这d个数是循环的,比如3 1 2 3就是第1天的价格是1,第二天的价格是2,第三天的价格是3,第四天的价格是1,其中0表示当天没有航班。现在问你让你和警察周旋k后到达第n个地方所要花费的最小费用是多少?

代码如下:

#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<string>
using namespace std;
const int maxint=999999;
int dp[1001][11];
vector<int> price[11][11];
void ini()
{
    memset(dp,0,sizeof(dp));
    for(int i=0;i<=10;i++)
    dp[0][i]=-1;
    for(int i=1;i<=1000;i++)
    for(int j=1;j<=10;j++)
    dp[i][j]=maxint;
    for(int i=0;i<=10;i++)
    for(int j=0;j<=10;j++)
    price[i][j].clear();
}
int getprice(int from,int to,int day)
{
    int len=price[from][to].size();
    return price[from][to][(day-1)%len];
}
int n,k,m;
int main()
{
    int tem,index=1;
    ios::sync_with_stdio(false);
    while(cin>>n>>k,n+k)
    {
        ini();
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(i!=j)
                {
                    cin>>m;
                    for(int q=1;q<=m;q++)
                    {
                        cin>>tem;
                        price[i][j].push_back(tem);
                    }
                }
            }
        }
        dp[0][1]=0;dp[1][1]=-1;
        for(int i=1;i<=k;i++)
        {
            for(int j=1;j<=n;j++)
            {
                tem=maxint;
                if(dp[i][j]==-1)
                continue;
                for(int q=1;q<=n;q++)
                {

                    if(q!=j&&dp[i-1][q]!=-1&&getprice(q,j,i)!=0)
                    tem=min(tem,dp[i-1][q]+getprice(q,j,i));

                }
                dp[i][j]=tem;
            }
        }
        cout<<"Scenario #"<<index++<<endl;
        if(dp[k][n]==maxint)
        cout<<"No flight possible."<<endl;
        else
        cout<<"The best flight costs "<<dp[k][n]<<"."<<endl;
        cout<<endl;
    }
    return 0;
}

思路:
简单的动态规划题目,转移方程并不难想。状态可以设置成3个也可以设置成2个,我设置成两个,其转移方程为dp[i][j]=min(dp[i][j],dp[i-1][q]+getprice(q,j,i)); 第一个状态时是天数,第二个状态是当前要去的位置,所以当前天数i要去的位置j=min(前一天所到达的位置q且该位置不是j+从q到j在第i天的票价)

注意:
每个结果输出两个换行,否则wa。

内容概要:本文针对火电厂参与直购交易挤占风电上网空间的问题,提出了一种风火打捆参与大用户直购交易的新模式。通过分析可再生能源配额机制下的双边博弈关系,建立了基于动态非合作博弈理论的博弈模型,以直购电价和直购电量为决策变量,实现双方收益均衡最大化。论文论证了纳什均衡的存在性,并提出了基于纳什谈判法的风-火利益分配方法。算例结果表明,该模式能够增加各方收益、促进风电消纳并提高电网灵活性。文中详细介绍了模型构建、成本计算和博弈均衡的实现过程,并通过Python代码复现了模型,包括参数定义、收益函数、纳什均衡求解、利益分配及可视化分析等功能。 适合人群:电力系统研究人员、能源政策制定者、从事电力市场交易的工程师和分析师。 使用场景及目标:①帮助理解风火打捆参与大用户直购交易的博弈机制;②为电力市场设计提供理论依据和技术支持;③评估不同政策(如可再生能源配额)对电力市场的影响;④通过代码实现和可视化工具辅助教学和研究。 其他说明:该研究不仅提供了理论分析,还通过详细的代码实现和算例验证了模型的有效性,为实际应用提供了参考。此外,论文还探讨了不同场景下的敏感性分析,如证书价格、风电比例等对市场结果的影响,进一步丰富了研究内容。
资源下载链接为: https://pan.quark.cn/s/d37d4dbee12c A:计算机视觉,作为人工智能领域的关键分支,致力于赋予计算机系统 “看懂” 世界的能力,从图像、视频等视觉数据中提取有用信息并据此决策。 其发展历程颇为漫长。早期图像处理技术为其奠基,后续逐步探索三维信息提取,与人工智能结合,又经历数学理论深化、机器学习兴起,直至当下深度学习引领浪潮。如今,图像生成和合成技术不断发展,让计算机视觉更深入人们的日常生活。 计算机视觉综合了图像处理、机器学习、模式识别和深度学习等技术。深度学习兴起后,卷积神经网络成为核心工具,能自动提炼复杂图像特征。它的工作流程,首先是图像获取,用相机等设备捕获视觉信息并数字化;接着进行预处理,通过滤波、去噪等操作提升图像质量;然后进入关键的特征提取和描述环节,提炼图像关键信息;之后利用这些信息训练模型,学习视觉模式和规律;最终用于模式识别、分类、对象检测等实际应用。 在实际应用中,计算机视觉用途极为广泛。在安防领域,能进行人脸识别、目标跟踪,保障公共安全;在自动驾驶领域,帮助车辆识别道路、行人、交通标志,实现安全行驶;在医疗领域,辅助医生分析医学影像,进行疾病诊断;在工业领域,用于产品质量检测、机器人操作引导等。 不过,计算机视觉发展也面临挑战。比如图像生成技术带来深度伪造风险,虚假图像和视频可能误导大众、扰乱秩序。为此,各界积极研究检测技术,以应对这一问题。随着技术持续进步,计算机视觉有望在更多领域发挥更大作用,进一步改变人们的生活和工作方式 。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值