File tree Expand file tree Collapse file tree 2 files changed +105
-0
lines changed Expand file tree Collapse file tree 2 files changed +105
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ using namespace std ;
3
+
4
+ vector<int > v;
5
+ long long dp[55 ][255 ];
6
+
7
+ long long go (int i, int n) {
8
+ if (n == 0 ) return 1 ;
9
+ if (i == v.size () || n < 0 ) return 0 ;
10
+ if (dp[i][n] != -1 ) return dp[i][n];
11
+
12
+ long long ans = 0 ;
13
+ for (int j = i; j < v.size (); ++j) {
14
+ long long a = 0 ;
15
+ if (n - v[j] >= 0 ) {
16
+ a = go (j, n - v[j]);
17
+ }
18
+ ans += a;
19
+ }
20
+
21
+ return dp[i][n] = ans;
22
+ }
23
+
24
+ int main () {
25
+ int n, m;
26
+ cin >> n >> m;
27
+
28
+ for (int i = 0 ; i < m; ++i) {
29
+ int c;
30
+ cin >> c;
31
+ v.push_back (c);
32
+ }
33
+
34
+ memset (dp, -1 , sizeof dp);
35
+ long long ans = go (0 , n);
36
+ cout << (n == 0 ? 0 : ans) << endl;
37
+
38
+ return 0 ;
39
+ }
40
+
Original file line number Diff line number Diff line change
1
+ #include < map>
2
+ #include < set>
3
+ #include < list>
4
+ #include < cmath>
5
+ #include < ctime>
6
+ #include < deque>
7
+ #include < queue>
8
+ #include < stack>
9
+ #include < bitset>
10
+ #include < cstdio>
11
+ #include < vector>
12
+ #include < cstdlib>
13
+ #include < numeric>
14
+ #include < sstream>
15
+ #include < iostream>
16
+ #include < algorithm>
17
+ using namespace std ;
18
+ /* Head ends here */
19
+ void print (vector<int > ar){
20
+ for (int i=0 ;i<ar.size ();i++){
21
+ if (i>0 ) cout << " " ;
22
+ cout << ar[i];
23
+ }
24
+ cout << endl;
25
+ }
26
+
27
+ void insertionSort (vector <int > ar) {
28
+ int t = ar.size (),f = 0 ;
29
+ int last = ar[t-1 ];
30
+ if (t==1 ) print (ar);
31
+ else {
32
+ for (int i=t-2 ; i>=0 ; i--){
33
+ if (last > ar[i]){
34
+ ar[i+1 ] = last;
35
+ print (ar);
36
+ break ;
37
+ }
38
+ else {
39
+ ar[i+1 ] = ar[i];
40
+ print (ar);
41
+ }
42
+ if (i==0 && !f) {
43
+ ar[0 ] = last;
44
+ print (ar);
45
+ break ;
46
+ }
47
+ }
48
+ }
49
+ }
50
+
51
+ /* Tail starts here */
52
+ int main () {
53
+ vector <int > _ar;
54
+ int _ar_size;
55
+ cin >> _ar_size;
56
+ for (int _ar_i=0 ; _ar_i<_ar_size; _ar_i++) {
57
+ int _ar_tmp;
58
+ cin >> _ar_tmp;
59
+ _ar.push_back (_ar_tmp);
60
+ }
61
+
62
+ insertionSort (_ar);
63
+
64
+ return 0 ;
65
+ }
You can’t perform that action at this time.
0 commit comments