hdu 4284 Travel(压缩DP,4级)

旅行计划与财务预算
文章讨论了PP如何在有限预算下规划旅行路线,包括选择城市、获取工作许可和计算成本,确保所有选定城市都能访问并获得工作许可。

Travel

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2641    Accepted Submission(s): 724


Problem Description
  PP loves travel. Her dream is to travel around country A which consists of N cities and M roads connecting them. PP has measured the money each road costs. But she still has one more problem: she doesn't have enough money. So she must work during her travel. She has chosen some cities that she must visit and stay to work. In City_i she can do some work to earn Ci money, but before that she has to pay Di money to get the work license. She can't work in that city if she doesn't get the license but she can go through the city without license. In each chosen city, PP can only earn money and get license once. In other cities, she will not earn or pay money so that you can consider Ci=Di=0. Please help her make a plan to visit all chosen cities and get license in all of them under all rules above.
  PP lives in city 1, and she will start her journey from city 1. and end her journey at city 1 too.
 

Input
  The first line of input consists of one integer T which means T cases will follow.
  Then follows T cases, each of which begins with three integers: the number of cities N (N <= 100) , number of roads M (M <= 5000) and her initiative money Money (Money <= 10^5) .
  Then follows M lines. Each contains three integers u, v, w, which means there is a road between city u and city v and the cost is w. u and v are between 1 and N (inclusive), w <= 10^5.
  Then follows a integer H (H <= 15) , which is the number of chosen cities.
  Then follows H lines. Each contains three integers Num, Ci, Di, which means the i_th chosen city number and Ci, Di described above.(Ci, Di <= 10^5)
 

Output
  If PP can visit all chosen cities and get all licenses, output "YES", otherwise output "NO".
 

Sample Input
  
2 4 5 10 1 2 1 2 3 2 1 3 2 1 4 1 3 4 2 3 1 8 5 2 5 2 3 10 1 2 1 100 1 2 10000 1 2 100000 1
 

Sample Output
  
YES NO
 

Source
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:   4268  4269  4270  4271  4272 

预处理两点距离,然后压缩DP。

dp[mask][k];最后在k 走过状态mask

注意重边


#include <iostream>
#include <cstring>
#include <cstdio>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define clr(f,z) memset(f,z,sizeof(f))
#define ll(x) (1<<x)
using namespace std;
const int mp=109;
const int oo=0x3f3f3f3f;
int g[mp][mp],dis[mp][mp],C[mp],D[mp],id[mp];
int dp[ ll(16) ][16];
int n,m,money;

int main()
{
    int cas,a,b,c,H;
    while(~scanf("%d",&cas))
    {
      while(cas--)
      {
        clr(g,0x3f);
        scanf("%d%d%d",&n,&m,&money);
        FOR(i,1,m)
        {
          scanf("%d%d%d",&a,&b,&c);
          g[a][b]=g[b][a]=min(g[a][b],c);
        }

        scanf("%d",&H);
        FOR(i,0,H-1)
        {
          scanf("%d%d%d",&id[i],&C[i],&D[i]);
        }

        clr(dis,0x3f);
        FOR(i,1,n)
        g[i][i]=0;
        FOR(i,1,n)FOR(j,1,n)FOR(k,1,n)
        {
          g[j][k]=min(g[j][k],g[j][i]+g[i][k]);
        }

        clr(dp,-1);
        int zzz = ll(H)-1,then;
        FOR(i,0,H-1)
        if(money >= g[1][ id[i] ] + D[i])
        dp[ ll(i) ][i] = money - g[1][ id[i] ] - D[i] + C[i];

        FOR(i,1,zzz)FOR(j,0,H-1)FOR(k,0,H-1)
        if(j != k && (i&ll(k)) && (i&ll(j)) && dp[ i^ll(j) ][k] != -1)
        {
          then = i^ll(j);
          if(dp[then][k] >= g[ id[k] ][ id[j] ] + D[j])
            dp[i][j] = max(dp[i][j],dp[then][k] - g[ id[k] ][ id[j] ] - D[j] + C[j]);
        }

        bool flag=0;
        FOR(i,0,H-1)
        if(dp[zzz][i]>=g[ id[i] ][1])
          flag=1;
        if(flag)puts("YES");
        else puts("NO");
      }
    }
    return 0;
}




内容概要:本文介绍了一种基于蒙特卡洛模拟和拉格朗日优化方法的电动汽车充电站有序充电调度策略,重点针对分时电价机制下的分散式优化问题。通过Matlab代码实现,构建了考虑用户充电需求、电网负荷平衡及电价波动的数学模【电动汽车充电站有序充电调度的分散式优化】基于蒙特卡诺和拉格朗日的电动汽车优化调度(分时电价调度)(Matlab代码实现)型,采用拉格朗日乘子法处理约束条件,结合蒙特卡洛方法模拟大量电动汽车的随机充电行为,实现对充电功率和时间的优化分配,旨在降低用户充电成本、平抑电网峰谷差并提升充电站运营效率。该方法体现了智能优化算法在电力系统调度中的实际应用价值。; 适合人群:具备一定电力系统基础知识和Matlab编程能力的研究生、科研人员及从事新能源汽车、智能电网相关领域的工程技术人员。; 使用场景及目标:①研究电动汽车有序充电调度策略的设计与仿真;②学习蒙特卡洛模拟与拉格朗日优化在能源系统中的联合应用;③掌握基于分时电价的需求响应优化建模方法;④为微电网、充电站运营管理提供技术支持和决策参考。; 阅读建议:建议读者结合Matlab代码深入理解算法实现细节,重点关注目标函数构建、约束条件处理及优化求解过程,可尝试调整参数设置以观察不同场景下的调度效果,进一步拓展至多目标优化或多类型负荷协调调度的研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值