mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
parent
2cd2040d4f
commit
cf696db349
57
QUSTOJ/1061_MyCodeBattle.cpp
Normal file
57
QUSTOJ/1061_MyCodeBattle.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
#include <bits/stdc++.h>
|
||||
#define LL long long
|
||||
using namespace std;
|
||||
const int VMAXN = 2e4 + 10;
|
||||
const int TMAXN = 100 + 10;
|
||||
const int INF = 0x3f3f3f3f;
|
||||
|
||||
int num[TMAXN], dp[VMAXN], k, n, m;
|
||||
int ans[TMAXN];
|
||||
|
||||
bool Check(int sum)
|
||||
{
|
||||
int &cur = dp[sum];
|
||||
if (cur != -1)
|
||||
return cur;
|
||||
if (sum == 0)
|
||||
return cur = 1;
|
||||
for (int i = 0; i < k; i++)
|
||||
if (sum >= ans[i] && Check(sum - ans[i]))
|
||||
return cur = 1;
|
||||
return cur = 0;
|
||||
}
|
||||
|
||||
void DFSID(int cur, int dep)
|
||||
{
|
||||
if (dep == k)
|
||||
{
|
||||
memset(dp, -1, sizeof dp);
|
||||
if (Check(n))
|
||||
{
|
||||
printf("%d", k);
|
||||
for (int i = 0; i < dep; i++)
|
||||
printf(" %d", ans[i]);
|
||||
puts("");
|
||||
exit(0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (cur >= m)
|
||||
return;
|
||||
ans[dep] = num[cur];
|
||||
DFSID(cur + 1, dep + 1);
|
||||
DFSID(cur + 1, dep);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
//freopen("input.txt", "r", stdin);
|
||||
int i, j;
|
||||
scanf("%d%d", &n, &m);
|
||||
for (i = 0; i < m; i++)
|
||||
scanf("%d", &num[i]);
|
||||
sort(num, num + m);
|
||||
for (k = 1; k <= m; k++)
|
||||
DFSID(0, 0);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user