LITTLE SHOP OF FLOWERS

本文介绍了一种使用动态规划(DP)解决花卉在花瓶中最佳排列的问题,目的是最大化整体美观价值。考虑到花卉种类和花瓶数量,通过特定的DP策略实现最优解。

http://poj.org/problem?id=1157

dp简单题,数据不强,接下来给出多种定义的dp,熟练熟练自己的dp

LITTLE SHOP OF FLOWERS
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 19763 Accepted: 9101

Description

You want to arrange the window of your flower shop in a most pleasant way. You have F bunches of flowers, each being of a different kind, and at least as many vases ordered in a row. The vases are glued onto the shelf and are numbered consecutively 1 through V, where V is the number of vases, from left to right so that the vase 1 is the leftmost, and the vase V is the rightmost vase. The bunches are moveable and are uniquely identified by integers between 1 and F. These id-numbers have a significance: They determine the required order of appearance of the flower bunches in the row of vases so that the bunch i must be in a vase to the left of the vase containing bunch j whenever i < j. Suppose, for example, you have bunch of azaleas (id-number=1), a bunch of begonias (id-number=2) and a bunch of carnations (id-number=3). Now, all the bunches must be put into the vases keeping their id-numbers in order. The bunch of azaleas must be in a vase to the left of begonias, and the bunch of begonias must be in a vase to the left of carnations. If there are more vases than bunches of flowers then the excess will be left empty. A vase can hold only one bunch of flowers. 

Each vase has a distinct characteristic (just like flowers do). Hence, putting a bunch of flowers in a vase results in a certain aesthetic value, expressed by an integer. The aesthetic values are presented in a table as shown below. Leaving a vase empty has an aesthetic value of 0. 
 

V A S E S

1

2

3

4

5

Bunches

1 (azaleas)

723-5-2416

2 (begonias)

521-41023

3 (carnations)

-21

5-4-2020

According to the table, azaleas, for example, would look great in vase 2, but they would look awful in vase 4. 

To achieve the most pleasant effect you have to maximize the sum of aesthetic values for the arrangement while keeping the required ordering of the flowers. If more than one arrangement has the maximal sum value, any one of them will be acceptable. You have to produce exactly one arrangement. 

Input

  • The first line contains two numbers: FV.
  • The following F lines: Each of these lines contains V integers, so that Aij is given as the jth number on the (i+1)st line of the input file.


  • 1 <= F <= 100 where F is the number of the bunches of flowers. The bunches are numbered 1 through F. 
  • F <= V <= 100 where V is the number of vases. 
  • -50 <= Aij <= 50 where Aij is the aesthetic value obtained by putting the flower bunch i into the vase j.

Output

The first line will contain the sum of aesthetic values for your arrangement.

Sample Input

3 5
7 23 -5 -24 16
5 21 -4 10 23
-21 5 -4 -20 20

Sample Output

53
这里的dp定义的是dp[i][j]为第i朵花放在第j个位置的时候获得的最大的值

那么有dp[i][j]=Max(dp[i-1][k],i-1<=k<=j-1)+a[i][j];

初始化:由于当前状态的值得获得需要知道上一个状态dp[i-1][i-1]------dp[i-1][j-1];那么边界只是一个一维的第一行,表达能力有限。。。

#include <cstdio>
const int maxn=1<<30;
int a[110][110],dp[110][110];
int main()
{
    int f,v;
    scanf("%d%d",&f,&v);
    for(int i=1;i<=f;i++)
        for(int j=1;j<=v;j++)
            scanf("%d",&a[i][j]);
    for(int i=1;i<=v;i++)
        dp[1][i]=a[1][i];
    for(int i=1;i<=f;i++)
    for(int j=i;j<=v;j++){
        int Max=-maxn;
        for(int k=i-1;k<=j-1;k++)
            if(Max<dp[i-1][k])Max=dp[i-1][k];
        dp[i][j]=Max+a[i][j];
    }
    int Max=-maxn;
    for(int i=f;i<=v;i++)
        if(dp[f][i]>Max)Max=dp[f][i];
    printf("%d\n",Max);
    return 0;
}


Little定律是计算机科学与性能分析领域中的一个基本原理,广泛应用于队列理论、系统设计、网络性能评估等方面。该定律由John D. C. Little在1961年提出,描述了系统中平均客户数量(L)、平均到达率(λ)和平均客户在系统中停留时间(W)之间的关系。其数学表达式为: $$ L = \lambda \times W $$ 该公式表明,系统的平均客户数量等于平均到达率乘以客户在系统中的平均停留时间。这一关系适用于广泛的排队系统,只要系统满足稳定状态的条件,即没有无限增长的客户队列。 在计算机科学中,Little定律被广泛用于性能分析和系统优化。例如,在评估服务器响应时间时,如果已知系统的平均请求数量(L)和平均请求处理时间(W),可以通过该公式计算出请求到达率(λ)。同样,在评估网络延迟或任务调度系统时,Little定律也提供了一个理论框架来理解系统行为[^1]。 ### 应用示例 在实际系统中,Little定律可以用于以下场景: - **服务器性能评估**:通过测量服务器的请求数量和请求处理时间,可以推导出系统的吞吐量。 - **缓存系统优化**:分析缓存命中与未命中对系统响应时间的影响,从而优化缓存策略。 - **网络流量分析**:用于估算网络中数据包的平均等待时间或队列长度。 ### 代码示例 以下是一个简单的Python代码片段,用于演示如何根据Little定律计算系统中的平均客户数量: ```python def calculate_little_law(arrival_rate, average_time_in_system): """ 根据Little定律计算平均客户数量 :param arrival_rate: 平均到达率 (λ) :param average_time_in_system: 客户在系统中的平均停留时间 (W) :return: 平均客户数量 (L) """ return arrival_rate * average_time_in_system # 示例:计算系统中平均客户数量 arrival_rate = 100 # 每秒到达100个请求 average_time_in_system = 0.5 # 每个请求平均处理时间为0.5秒 average_customers_in_system = calculate_little_law(arrival_rate, average_time_in_system) print(f"系统中平均客户数量 (L): {average_customers_in_system}") ``` 运行结果: ``` 系统中平均客户数量 (L): 50.0 ``` 该示例展示了如何通过Little定律快速估算系统的负载情况,为性能调优提供依据。 ### 限制与适用条件 尽管Little定律具有广泛的适用性,但其有效性依赖于以下条件: - 系统必须处于稳定状态,即客户到达率和离开率保持平衡。 - 系统不应存在外部干扰或突发性负载,否则可能导致估算结果偏差。 - Little定律不依赖于具体的到达分布或服务时间分布,但要求这些参数在整个系统运行期间保持相对稳定。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值