HDU4283 You Are the One4(区间DP 难)(*)

探讨一个通过调整序列中个体的出场顺序,以最小化总屌丝值的算法问题。利用动态规划方法,考虑如何使用栈来优化序列,减少等待导致的不幸福感。

题目链接
Problem Description
  The TV shows such as You Are the One has been very popular. In order to meet the need of boys who are still single, TJUT hold the show itself. The show is hold in the Small hall, so it attract a lot of boys and girls. Now there are n boys enrolling in. At the beginning, the n boys stand in a row and go to the stage one by one. However, the director suddenly knows that very boy has a value of diaosi D, if the boy is k-th one go to the stage, the unhappiness of him will be (k-1)*D, because he has to wait for (k-1) people. Luckily, there is a dark room in the Small hall, so the director can put the boy into the dark room temporarily and let the boys behind his go to stage before him. For the dark room is very narrow, the boy who first get into dark room has to leave last. The director wants to change the order of boys by the dark room, so the summary of unhappiness will be least. Can you help him?

Input
  The first line contains a single integer T, the number of test cases. For each case, the first line is n (0 < n <= 100)
  The next n line are n integer D1-Dn means the value of diaosi of boys (0 <= Di <= 100)

Output
  For each test case, output the least summary of unhappiness .

Sample Input
2
  
5
1
2
3
4
5

5
5
4
3
2
2

Sample Output
Case #1: 20
Case #2: 24

Source
2012 ACM/ICPC Asia Regional Tianjin Online
题意:给定一个序列,序列内的人有屌丝值Di,第i个人如果是第k个出场,那么他的屌丝值为Di * (k-1), 但是导演可以通过一个栈来调整序列里面人的出场顺序。
求一个出场序列使总屌丝值最小。

#include<bits/stdc++.h> 
using namespace std;
const int maxn =205;
typedef long long ll;
const ll inf=1e18;
ll sum[maxn],dp[maxn][maxn],a[maxn];
int main()
{
    int T,x,n;
    scanf("%d",&T);
    for(int s=1;s<=T;++s)
    {
        scanf("%d",&n);
        sum[0]=0;
        for(int i=1;i<=n;++i) scanf("%lld",&a[i]),sum[i]=sum[i-1]+a[i];
        for(int i=1;i<=n;++i)
        {
            for(int j=1;j<=n;++j) dp[i][j]=inf;
            dp[i][i]=0;
        }
        for(int len=2;len<=n;++len)
        {
            for(int l=1;l+len-1<=n;++l)
            {
                int r=l+len-1;
                dp[l][r]=min(dp[l+1][r]+sum[r]-sum[l],dp[l+1][r]+(r-l)*a[l]);
                for(int k=l+1;k<r;++k)
                dp[l][r]=min(dp[l][r],dp[l+1][k]+a[l]*(k-l)+dp[k+1][r]+(sum[r]-sum[k])*(k-l+1));
            }
        }
        printf("Case #%d: %lld\n",s,dp[1][n]);
    }
}
基于STM32F103单片机,设计了一款智能火灾烟雾检测报警器。该系统能够实时监测环境中的烟雾浓度,并在检测到烟雾浓度超过预设阈值时触发报警,有效预防火灾事故的发生。 主要功能 烟雾浓度检测:通过MQ-135烟雾传感器实时采集环境中的烟雾浓度数据。 LCD显示:使用LCD1602液晶显示屏实时显示当前的烟雾浓度值。 报警功能:当烟雾浓度超过预设阈值时,系统会通过蜂鸣器发出报警信号。 阈值设置:用户可以通过按键设置烟雾浓度的报警阈值,设置的阈值会存储在单片机的Flash中,掉电不丢失。 硬件设计 核心板:采用STM32F103C8T6单片机作为控制核心。 传感器:使用MQ-135烟雾传感器进行烟雾浓度检测。 显示模块:采用LCD1602液晶显示屏显示烟雾浓度。 报警模块:使用蜂鸣器作为报警装置。 按键模块:提供三个按键用于设置烟雾浓度的报警阈值。 软件设计 数据采集:通过AD转换将传感器采集的模拟信号转换为数字信号。 数据处理:对采集到的数据进行处理,计算出实际的烟雾浓度值。 报警逻辑:当烟雾浓度超过预设阈值时,触发报警逻辑,控制蜂鸣器发出报警信号。 阈值设置:通过按键设置烟雾浓度的报警阈值,并将设置的阈值存储在单片机的Flash中。 使用说明 系统启动:上电后,系统自动启动,开始检测环境中的烟雾浓度。 显示查看:通过LCD1602液晶显示屏查看当前的烟雾浓度值。 阈值设置:按下设置键进入阈值设置模式,通过设置+和设置-键调整阈值,设置完成后系统自动保存。 报警触发:当烟雾浓度超过预设阈值时,蜂鸣器会发出报警信号,提醒用户注意。 注意事项 传感器通电后需要预热20秒左右,测量的数据才会稳定。 传感器发热属于正常现象,因为内部有电热丝。 系统设计时考虑了功耗控制,但在长时间使用时仍需注意电源管理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值