Hurdles of 110m ZOJ - 2972 (DP)

本文介绍了一道关于刘翔参加110米跨栏比赛的算法题目,选手需在不同模式下选择最佳跑步策略以达到最短完成时间。文章详细解释了问题背景及输入输出示例。

Hurdles of 110m

ZOJ - 2972

In the year 2008, the 29th Olympic Games will be held in Beijing. This will signify the prosperity of China and Beijing Olympics is to be a festival for people all over the world as well.

Liu Xiang is one of the famous Olympic athletes in China. In 2002 Liu broke Renaldo Nehemiah's 24-year-old world junior record for the 110m hurdles. At the 2004 Athens Olympics Games, he won the gold medal in the end. Although he was not considered as a favorite for the gold, in the final, Liu's technique was nearly perfect as he barely touched the sixth hurdle and cleared all of the others cleanly. He powered to a victory of almost three meters. In doing so, he tied the 11-year-old world record of 12.91 seconds. Liu was the first Chinese man to win an Olympic gold medal in track and field. Only 21 years old at the time of his victory, Liu vowed to defend his title when the Olympics come to Beijing in 2008.

In the 110m hurdle competition, the track was divided into N parts by the hurdle. In each part, the player has to run in the same speed; otherwise he may hit the hurdle. In fact, there are 3 modes to choose in each part for an athlete -- Fast Mode, Normal Mode and Slow Mode. Fast Mode costs the player T1 time to pass the part. However, he cannot always use this mode in all parts, because he needs to consume F1 force at the same time. If he doesn't have enough force, he cannot run in the part at the Fast Mode. Normal Mode costs the player T2 time for the part. And at this mode, the player's force will remain unchanged. Slow Mode costs the player T3 time to pass the part. Meanwhile, the player will earn F2 force as compensation. The maximal force of a player is M. If he already has M force, he cannot earn any more force. At the beginning of the competition, the player has the maximal force.

The input of this problem is detail data for Liu Xiang. Your task is to help him to choose proper mode in each part to finish the competition in the shortest time.


Input

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 50) which is the number of test cases. And it will be followed by T consecutive test cases.

Each test case begins with two positive integers N and M. And following N lines denote the data for the N parts. Each line has five positive integers T1 T2 T3 F1 F2. All the integers in this problem are less than or equal to 110.

Output

Results should be directed to standard output. The output of each test case should be a single integer in one line, which is the shortest time that Liu Xiang can finish the competition.

Sample Input
2
1 10
1 2 3 10 10
4 10
1 2 3 10 10
1 10 10 10 10
1 1 2 10 10
1 10 10 10 10

Sample Output
1
6

Hint

For the second sample test case, Liu Xiang should run with the sequence of Normal Mode, Fast Mode, Slow Mode and Fast Mode.

跨栏跑分为几段,每段有三种跑步方式,不同方式通过每段路程时间不同,并消耗或补充体力,要求输出最短时间。

code:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int inf = 0x3f3f3f3f;
int dp[200][500];
int main(){
    int T;
    cin >> T;
    while (T--)
    {
        int n, m;
        scanf("%d %d", &n, &m);
        for (int i = 1; i < 200; i++)
            memset(dp[i], inf, sizeof (dp[i]));
        memset(dp[0], 0, sizeof(dp[0]));
        for (int i = 1; i <= n; i++)
        {
            int t1, t2, t3, f1, f2;
            scanf("%d %d %d %d %d", &t1, &t2, &t3, &f1, &f2);
            for (int j = 0; j <= m; j++)
            {
                if (j >= f1)
                    dp[i][j-f1] = min(dp[i][j-f1], dp[i-1][j] + t1);//如果可以使用模式1

                dp[i][j] = min(dp[i][j], dp[i-1][j] + t2);//模式2

                if (j + f2 >= m)//模式3
                    dp[i][m] = min(dp[i][m], dp[i-1][j] + t3);
                else
                    dp[i][j+f2] = min(dp[i][j+f2], dp[i-1][j] + t3);
            }
        }
        int ans = inf;
        for (int i = 0; i <= m; i++)
        {
            ans = min(ans, dp[n][i]);
        }
        printf("%d\n", ans);
    }
    return 0;
}



### DROID-SPLAT Framework Overview In the IT context, **DROID-SPLAT** refers to a specialized framework or tool designed primarily for analyzing and managing large-scale data streams within distributed systems environments. The term "DROID" stands for Distributed Robust Object Identification, while "SPLAT" is an acronym for Scalable Parallel Log Analysis Toolkit[^1]. Together, they form a comprehensive solution aimed at addressing challenges related to log analysis, object identification, and performance optimization in high-throughput computing scenarios. The primary objectives of this framework include: #### 1. Data Stream Processing DROID-SPLAT excels in processing continuous data streams from various sources such as network traffic logs, application activity records, and sensor outputs. It employs advanced algorithms tailored for real-time analytics, ensuring minimal latency during critical operations[^2]. ```python import droid_splat as ds # Example usage of DROID-SPLAT API for stream processing stream_processor = ds.StreamProcessor() data_stream = stream_processor.read_from_source('network_traffic_logs') processed_data = stream_processor.analyze(data_stream) ``` #### 2. Distributed Architecture Support This framework leverages distributed architecture principles by dividing tasks across multiple nodes in a cluster environment. This approach enhances scalability and fault tolerance significantly compared to traditional monolithic solutions[^3]. #### 3. Performance Optimization Techniques To ensure optimal resource utilization, DROID-SPLAT incorporates several cutting-edge techniques like adaptive load balancing, dynamic task scheduling, and intelligent caching mechanisms that adapt based on workload characteristics[^4]. --- ### Implementation Considerations When implementing DROID-SPLAT into existing infrastructures, organizations must carefully evaluate compatibility with current technologies stack along with potential integration hurdles. Additionally, proper training programs should be established so staff members can effectively utilize its full capabilities without unnecessary complications arising due lack familiarity[^5].
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值