zoukankan      html  css  js  c++  java
  • URAL

    While some people travel in space from planet to planet and discover new worlds, the others who live on Earth still have to get up in the morning, go to work, return back home and try to have a rest. They don't like this situation anymore and envy people who can afford space travel.
    That doesn't suit the government of the Earth. Their goal is to make everyone happy, but that is difficult. That is why the government decided to do some tests in the small town of Lux, and then, if everything goes well, to apply the experience to other cities.
    Lux's distinctive feature is that it is situated in a long underground tunnel and there is only one train inside it. Almost everyone in the town uses the train. The government has bought a brainwashing device and installed it in the train. The device is new and its effects aren't well understood yet, so the government decided to limit the number of the spans where the device would be turned on. Statistics on number of passengers travelling between each pair of stations every morning have already been collected. Now the government should pick the spans where the device could be used to make most of the people happy.

    Input

    The first line contains integers n and k that are the total number of the stations and the number of spans between adjacent stations where the device could be turned on (2 ≤ n ≤ 500; 1 ≤ k ≤ n − 1). The i'th of the next n − 1 lines contains n −i integers. The j'th integer is the number of passengers traveling from i'th to ( ij)'th station. These numbers are non-negative and don't exceed 100. You can assume that every passenger uses the train only once a day.

    Output

    In the first line output the total number of people who will become happy because of the device. In the second line output k integers in the ascending order that are the indexes of the spans where the device should be turned on. The span between the station i and i + 1 has the index i. If the problem has multiple solutions you can output any of them.

    Example

    inputoutput
    4 1
    5 0 6
    5 3
    5
    
    14
    3
    

    思路:先预处理出g[i][j]:表示在边j-1,j上放个洗脑机器时,从去区间[i,j)中出发经过边j-1,j的被洗脑人数。

      dp[i][j]表示前i个点中放了j个洗脑机器,并且边i-1,i上放了洗脑机器时最大的洗脑人数。

     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 #define MP make_pair
     6 #define PB push_back
     7 typedef long long LL;
     8 typedef pair<int,int> PII;
     9 const double eps=1e-8;
    10 const double pi=acos(-1.0);
    11 const int K=1e6+7;
    12 const int mod=1e9+7;
    13 
    14 
    15 int n,s,mx,ls,dp[600][600],g[600][600],sum[600][600],rd[600][600];
    16 void ptf(int x,int k)
    17 {
    18     if(k>0)
    19         ptf(rd[x][k],k-1),printf("%d ",x-1);
    20 }
    21 int main(void)
    22 {
    23     cin>>n>>s;
    24     for(int i=1;i<=n;i++)
    25         for(int j=i+1,x;j<=n;j++)
    26             scanf("%d",&g[i][j]),g[i][j]+=g[i][j-1];
    27     for(int i=1;i<n;i++)
    28     for(int j=i+1;j<=n;j++)
    29         for(int k=i;k<j;k++)
    30             sum[i][j]+=g[k][n]-g[k][j-1];
    31     memset(dp,-1,sizeof(dp));
    32     dp[1][0]=0,mx=-1;
    33     for(int i=1;i<=n;i++)
    34     for(int j=1;j<=s;j++)
    35     for(int k=j;k<i;k++)
    36         if(dp[k][j-1]+sum[k][i]>dp[i][j])
    37             dp[i][j]=dp[k][j-1]+sum[k][i],rd[i][j]=k;
    38     for(int i=s;i<=n;i++)
    39     if(dp[i][s]>mx)
    40     {
    41         mx=dp[i][s],ls=i;
    42     }
    43     printf("%d
    ",mx);
    44     ptf(ls,s);
    45     return 0;
    46 }
  • 相关阅读:
    pyhon简单比较文本相似度的方法
    MongoDB数据的导入、导出、备份与恢复
    django实现注册、登录小系统
    nginx+uwsgi部署django的简单介绍
    python操作Excel的几种方式
    Python的Pexpect的简单使用
    JVM之类加载
    Java中的绑定
    JVM之GC
    JVM之内存管理
  • 原文地址:https://www.cnblogs.com/weeping/p/6383745.html
Copyright © 2011-2022 走看看