比赛 201712练习 评测结果 AAAAAAAAAA
题目名称 硬币问题 最终得分 100
用户昵称 @@@ 运行时间 0.068 s
代码语言 C++ 内存使用 2.22 MiB
提交时间 2017-12-27 21:13:34
显示代码纯文本
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
int v[100001],s,n;
int a1[100001],a2[100001],out1[100001],out2[100001];
int fMin(int x)
{
	for(int i = 1;i <= n;i++)
	{
		if(x >= v[i])
		a1[x] = min(a1[x],a1[x-v[i]]);
	}
}
int main()
{
	freopen("kouka.in","r",stdin);
	freopen("kouka.out","w",stdout);
	cin >> n >> s;
	for(int i = 1;i <= n;i++)
	{
		scanf("%d",v+i);
		
	}
	for(int i = 1;i <= s;i++)
	{
		a1[i] = 99999999;
		a2[i] = -99999999;
	}
	for(int i = 1;i <= s;i ++)
	{
		for(int j = 1;j <= n;j++)
		{
			if(i >= v[j])
			{
				//a1[x] = min(a1[x],a1[x-v[j]]+1);
				if(a1[i-v[j]]+1 < a1[i])
				{
					a1[i] = a1[i-v[j]]+1;
					out1[i] = j;
				}
				if(a2[i-v[j]]+1 > a2[i])
				{
					a2[i] = a2[i-v[j]]+1;
					out2[i] = j;
				}
				//a2[x] = max(a2[x],a2[x-v[j]]+1);
			}
		}
	}
	int ans1 = a1[s],ans2 = a2[s];
	cout << ans1  <<  ' ' << ans2 << endl;
	int l1 = s,l2 = s;
	while(l1)
	{
		printf("%d ",out1[l1]);
		l1 -= v[out1[l1]];
	}
	cout << endl;
	while(l2)
	{
		printf("%d ",out2[l2]);
		l2 -= v[out2[l2]];
	}
	return 0;
}