UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#189971#3324. 树苗(tree)ddh123100390ms2716kbC++11683b2023-10-05 08:27:522023-10-05 12:32:06

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,K,a[21],dp[21][21][21][21],ans=1e18,A,B;
signed main(){
	cin>>n>>K;
	for(int i=1;i<=n;i++)cin>>a[i];
	memset(dp,0x3f,sizeof(dp));
	dp[0][0][0][0]=0;
	for(int i=1;i<=n;i++)for(int j=0;j<=K;j++)
	for(int l=1;l<=n;l++)for(int k=0;k<=n;k++){
		if(a[l]+k>=a[i])for(int tl=0;tl<=n;tl++)
		for(int tk=0;tk<=n;tk++){
			A=a[tl]+tk,B=a[l]+k;
			if(A<B&&!j)continue;
			if(A<B)dp[i][j][l][k]=min(dp[i][j][l][k],dp[i-1][j-1][tl][tk]+a[l]+k-a[i]);
			else dp[i][j][tl][tk]=min(dp[i][j][tl][tk],dp[i-1][j][tl][tk]);	
		}
		if(i==n&&j==K)ans=min(ans,dp[i][j][l][k]);
	}
	cout<<ans;						
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 80ms
memory: 2712kb

input:

20 20
941875906 3822781 449168967 380996194 74552217 351678383 338576429 283097025 621089816 1234573...

output:

9681131585

result:

ok single line: '9681131585'

Test #2:

score: 10
Accepted
time: 79ms
memory: 2712kb

input:

20 20
10527421 20948275 30261754 40147397 50420704 60722213 70623948 80280790 90554478 100845904 110...

output:

0

result:

ok single line: '0'

Test #3:

score: 10
Accepted
time: 80ms
memory: 2716kb

input:

20 20
375647377 694803432 405638673 452074257 316494968 812425781 410220501 947545545 44110880 85091...

output:

5689322908

result:

ok single line: '5689322908'

Test #4:

score: 10
Accepted
time: 1ms
memory: 2712kb

input:

5 1
3 1 1 5 5

output:

2

result:

ok single line: '2'

Test #5:

score: 10
Accepted
time: 0ms
memory: 2712kb

input:

5 3
2 2 5 1 3

output:

1

result:

ok single line: '1'

Test #6:

score: 10
Accepted
time: 0ms
memory: 2716kb

input:

5 2
1 3 5 4 3

output:

2

result:

ok single line: '2'

Test #7:

score: 10
Accepted
time: 34ms
memory: 2716kb

input:

20 8
871929662 439792376 687409670 637699165 203379564 510322553 505657251 897767419 304747573 85858...

output:

736612128

result:

ok single line: '736612128'

Test #8:

score: 10
Accepted
time: 59ms
memory: 2712kb

input:

20 14
10921365 20321584 30579098 40050141 50403179 60323927 70745971 80704811 90854918 100515713 110...

output:

56961014

result:

ok single line: '56961014'

Test #9:

score: 10
Accepted
time: 22ms
memory: 2712kb

input:

20 5
914351454 702197249 215474099 579049794 227028026 493073867 90377697 379425068 420699945 871931...

output:

273231451

result:

ok single line: '273231451'

Test #10:

score: 10
Accepted
time: 35ms
memory: 2712kb

input:

20 8
10866256 20629926 30221774 40863655 50628050 60358417 70313111 80777586 90253514 100514012 1100...

output:

116217608

result:

ok single line: '116217608'

Extra Test:

score: 0
Extra Test Passed