[Offer收割]编程练习赛4 register

Ended

Participants:899

Verdict:Accepted
Score:100 / 100
Submitted:2016-08-07 12:13:20

Lang:G++

Edit
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
#include<iostream>
#include<limits.h>
#include<string>
#include<fstream>
#include<queue>
#include<cstring>
#include <unordered_set>
#include <unordered_map>
using namespace std;
int search(int &N, int &X, int *d, int sum, int next) {
    int result = INT_MAX, temp;
    if (sum >= X) return sum;
    if (next >= N) return -1;
    for (int i = next; i<N; i++) {
        temp = search(N, X, d, sum + d[i], i + 1);
        if (temp != -1) {
            result = min(result, temp);
        }
    }
    return result;
}
int main() {
    int N, X;
    cin >> N >> X;
    int *d = new int[N];
    for (int i = 0; i<N; i++) {
        cin >> d[i];
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX