UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#212536#3842. 小t做晚餐2(cook)huangyuhang1001ms1264kbC++11792b2024-10-19 10:53:562024-10-19 12:34:25

answer

#include<bits/stdc++.h>
using namespace std;
int n,T,m;
int a[20+5];
bool cmp(int x,int y)
{
	return x>y;
}
int maxx;
vector<int>S;
void DFS(int res,int depth,vector<int>&D)
{
	if(res>T)
		return;
	if(depth==n+1)
	{
		if(res>maxx)
		{
			S=D;
			maxx=res;
		}
		
		return;
	}
	D.push_back(depth);
	DFS(res+a[depth],depth+1,D);
	D.pop_back();
	DFS(res,depth+1,D); 
}
int main()
{
	scanf("%d %d %d",&n,&T,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1,cmp);
	int cost=0;
//	int c=0;
	while(n)
	{
	//	cout<<++c<<' ';
		cost+=m;
		maxx=0;
		S.clear();
		vector<int>T_;
		DFS(0,1,T_);
		for(auto p:S)
		{
			a[p]=0;	
		}	
		sort(a+1,a+n+1,cmp);
		n-=S.size();
//		cout<<S.size()<<endl;
	}
	cout<<cost;
	return 0;
 } 

详细

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

Test #1:

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

input:

5 14 9
10 7 7 7 3

output:

27

result:

ok single line: '27'

Test #2:

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

input:

8 14 4
7 10 1 7 8 6 10 12

output:

20

result:

ok single line: '20'

Test #3:

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

input:

8 20 3
14 17 6 6 9 12 15 18

output:

18

result:

ok single line: '18'

Test #4:

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

input:

10 30 4
6 16 16 9 23 20 9 3 1 8

output:

16

result:

ok single line: '16'

Test #5:

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

input:

10 41 23
17 7 7 1 8 15 17 16 12 3

output:

69

result:

ok single line: '69'

Test #6:

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

input:

20 95400260 89673557
20487698 22301259 2829304 297290 1412988 16842716 23469759 30225551 23431967 16...

output:

358694228

result:

ok single line: '358694228'

Test #7:

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

input:

20 67248590 51724831
648120 20516501 13360885 3511712 27876258 27548361 19789779 14004233 13644809 8...

output:

206899324

result:

ok single line: '206899324'

Test #8:

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

input:

20 32236123 23129506
9697610 3181601 12248516 13725824 1976763 3805852 10010680 13270519 12901003 78...

output:

138777036

result:

ok single line: '138777036'

Test #9:

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

input:

20 50597385 71307217
20562436 23376499 14957779 2472920 13994843 22843456 16389516 13712272 24008015...

output:

427843302

result:

ok single line: '427843302'

Test #10:

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

input:

20 79575244 7977295
21610095 13701521 24651488 4567616 15005155 6234858 15956463 15009333 5191205 59...

output:

47863770

result:

ok single line: '47863770'