202209-1(如此编码)
题目链接:
计算机软件能力认证考试系统http://118.190.20.162/view.page?gpid=T153
题意:
![](https://i-blog.csdnimg.cn/blog_migrate/b864f8d9160c70dc5478103b77e0a69b.png)
思路:
对应求就行。
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<stack>
#include<cmath>
#include<unordered_set>
#define PII pair<int, int>
#define int long long
using namespace std;
const int N = 25;
int n, m;
int a[N];
void solve()
{
cin >> n >> m;
for (int i = 1; i <= n; ++ i) cin >> a[i];
int lc = 1, c = a[1], b = -1;
for (int i = 2; i <= n; ++ i)
{
int b = (m % c) / lc;
cout << b << ' ';
lc = c;
c *= a[i];
}
cout << m % c / lc;
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
// int T;
// cin >> T;
//
// while(T--)
// {
solve();
// }
return 0;
}
t2代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<stack>
#include<cmath>
#include<unordered_set>
#define PII pair<int, int>
#define int long long
using namespace std;
const int N = 35, M = 3e5 + 10;
int n, m, sum;
int a[N], f[N][M];
void solve()
{
cin >> n >> m;
for (int i = 1; i <= n; ++ i)
{
cin >> a[i];
sum += a[i];
}
sort(a + 1, a + n + 1);
int k = sum - m;
for (int i = 1; i <= n; ++ i)
for (int j = 1; j <= k; ++ j)
{
f[i][j] = f[i - 1][j];
if(j >= a[i]) f[i][j] = max(f[i][j], f[i - 1][j - a[i]] + a[i]);
}
cout << sum - f[n][k] << endl;
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
// int T;
// cin >> T;
//
// while(T--)
// {
solve();
// }
return 0;
}