#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a[15];
int m, n;
int f[101][100005], vc = 1e9, tr[100005], ans[15];
ll tong = 0;
void nhap() {
cin >> m >> n;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
tong += a[i];
}
}
void truyvet()
{
int d[101];
for(int i=1;i<=n;i++) d[i]=1;
int n1=n;
while(n>0&&m>0)
{
// cout<<n<<" "<<m<<endl;
if(f[n][m]==f[n-1][m]){
n--;
}
else{
d[n]++;
m=m-a[n];
}
}
// cout<<n<<" "<<m<<endl;
for(int i=1;i<=n1;i++)
cout<<d[i]<<" ";
}
void dp1()
{ // cout<<m<<endl;
f[0][0]=0;
for(int j=1;j<=m;j++) f[1][j]=vc;
for(int j=1;j<=m/a[1];j++)
f[1][j*a[1]]=j;
for(int i=2;i<=n;i++)
{
for(int j=0;j<=m;j++)
{
f[i][j]=f[i-1][j];
if(j-a[i]>=0) f[i][j]=min(f[i][j],f[i][j-a[i]]+1);
}
}
/* for(int i=1;i<=n;i++){
for(int j=0;j<=m;j++) cout<<f[i][j]<<" ";
cout<<endl;
}*/
cout<<n+f[n][m]<<endl;
truyvet();
}
void giai() {
if(tong > m) {
cout << 0 << endl;
return;
}
if(tong == m) {
cout << n << endl;
for(int i=1;i<=n;i++) cout << 1 << ' ';
return;
}
m =m- tong;
dp1();
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
freopen("b.inp", "r", stdin);
freopen("b.out", "w", stdout);
nhap();
giai();
// solve();
}
* Chuyên dạy lập trình ONLINE cho học sinh THCS, THPT *.
Mọi giao lưu, trao đổi, xin liên hệ: Lê Quang Vinh - zalo: 037.803.8755.
Page: Lớp học Code Sky
Group FB1: Ôn thi HSG9 - THTB - TS10 chuyên tin
Group FB2: Học Scratch - Ôn thi Tin học trẻ bảng A
Chủ Nhật, 24 tháng 4, 2022
VANTAI C++
Đăng ký:
Đăng Nhận xét (Atom)
Không có nhận xét nào:
Đăng nhận xét
Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.