HDU 5777 BestCoder Round #85 domino (多米诺骨牌模拟)

网友投稿 229 2022-09-15

HDU 5777 BestCoder Round #85 domino (多米诺骨牌模拟)

domino

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 372    Accepted Submission(s): 202

Problem Description

Little White plays a game.There are n pieces of dominoes on the table in a row. He can choose a domino which hasn't fall down for at most k times, let it fall to the left or right. When a domino is toppled, it will knock down the erect domino. On the assumption that all of the tiles are fallen in the end, he can set the height of all dominoes, but he wants to minimize the sum of all dominoes height. The height of every domino is an integer and at least 1.

Input

The first line of input is an integer T ( 1≤T≤10) There are two lines of each test case. The first line has two integer n and k, respectively domino number and the number of opportunities.( 2≤k,n≤100000) The second line has n - 1 integers, the distance of adjacent domino d, 1≤d≤100000

Output

For each testcase, output of a line, the smallest sum of all dominoes height

Sample Input

1 4 2 2 3 4

Sample Output

9

Source

​​BestCoder Round #85​​

Recommend

wange2014   |   We have carefully selected several similar problems for you:  ​​5780​​​ ​​5779​​​ ​​5778​​​ ​​5775​​​ ​​5774​​

题意:

桌子上有n张多米诺骨牌排成一列。它有k次机会,每次可以选一个还没有倒的骨牌,向左或者向右推倒。每个骨 牌倒下的时候,若碰到了未倒下的骨牌,可以把它推倒。小白现在可以随意设置骨牌的高度,但是骨牌高度为整数,且至少为1,并且小白希望在能够推倒所有骨牌的前提下,使所有骨牌高度的和最小。

题解: 首先骨牌只要考虑都往右推,其次能带倒骨牌的前提是高度大于等于距离+1。然后模拟一下就可以了。

AC代码:

#includeusing namespace std;int n,k;int a[100010];bool vis[100010];int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&k); for(int i=1;i < n;i++) { scanf("%d",&a[i]); } n--; sort(a+1,a+n+1); long long sum=0; //n++; for(int i=1; i<= n; i++) //枚举距离 { sum+=a[i]; if(i>n-k+1) sum-=a[i]; } sum=sum+n+1; printf("%I64d\n",sum); } return 0;}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:姚振华与宝能的造车梦:千亿资本开路 野蛮人能否后来居上?
下一篇:HDU 5779 BestCoder Round #85 Tower Defence ( dp升级版 )
相关文章

 发表评论

暂时没有评论,来抢沙发吧~