-
Notifications
You must be signed in to change notification settings - Fork 1
/
Stamps.cpp
62 lines (55 loc) · 1.32 KB
/
Stamps.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
ID: zdzapple
LANG: C++
TASK: stamps
*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <climits>
#include <fstream>
#include <math.h>
#include <iomanip>
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
using namespace std;
const string input_file = "stamps.in";
const string out_file = "stamps.out";
ifstream fin;
ofstream fout;
void openfile() { fin.open(input_file.c_str()); fout.open(out_file.c_str()); }
void closefile() { fin.close(), fout.close(); }
int minstamps[10000 * (200 + 3) + 3];
int N, K;
int value[200];
int main()
{
openfile();
int i, j, k;
fin >> N >> K;
for (i = 0; i < K; ++ i)
fin >> value[i];
minstamps[0] = 0;
for (i = 1; i < 10000 * (200 + 3) + 3; ++i)
minstamps[i] = INT_MAX;
for (i = 1; ; ++i)
{
for (j = 0; j < K; ++ j)
{
if (value[j] <= i && minstamps[i-value[j]] + 1 < minstamps[i])
minstamps[i] = minstamps[i-value[j]] + 1;
}
if (minstamps[i] == INT_MAX || minstamps[i] > N)
break;
///cout << i << " " << minstamps[i] << endl;
}
fout << i-1 << endl;
closefile();
}