Untitled
unknown
plain_text
2 years ago
887 B
2
Indexable
#include<iostream> using namespace std; char temp[16]; int a[16]; int sl; int result; int arr[16]; int Sum; void out(){ for (int i = 0; i < sl; i++) { a[i] = temp[i] - 48; } } void Try(int i, int &Max){ for (int j = 0; j <= 1; j++) { temp[i - 1] = j + 48; if(i == sl){ out(); result = 0; for (int t = 0; t < sl; t++) { result += a[t]*arr[t]; } if(result <= Sum){ Max = max(Max, result); } }else{ Try(i + 1, Max); } } } int main(int argc, char** argv) { freopen("input.txt","r",stdin); int test_case; int T; int Max; // ios::sync_with_stdio(false); cin >> T; for(test_case = 1; test_case <= 10; ++test_case) { Max = 0; cin>>Sum; cin>>sl; for (int i = 0; i < sl; i++) { cin>>arr[i]; } Try(1, Max); cout << "#" << test_case << " " << Max << endl; } return 0; }
Editor is loading...