rt
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1e3 + 5;
int m[MAXN],n,c;
bool isread[MAXN];
int ans = -0x3f3f3f3f3f3f3f3f;
void dfs(int nowp,int nowm){
isread[nowp] = 1;
if(nowm > c){
ans = max(ans,nowm - m[nowp]);
return;
}
for(int i = 1; i <= n; i++){
if(isread[i] == 0){
isread[i] = 1;
dfs(i,nowm + m[i]);
isread[i] = 0;
}
}
}
signed main(){
cin >> n >> c;
for(int i = 1; i <= n; i++){
cin >> m[i];
}
for(int i = 1; i <= n; i++){
memset(isread,0,sizeof(isread));
dfs(i,m[i]);
}
cout << ans;
return 0;
}
试着输出了半道上的数据,一直在原地打转就是没法回溯
TLE输入:
36 968459818
21
51
104
163
301
482
788
1297
2123
3447
5574
9028
14606
23669
38309
61980
100299
162307
262636
424976
687619
1112634
1800259
2912907
4713201
7626142
12339362
19965513
32304910
52270456
84575394
136845869
221421265
358267166
579688458
937955633
正确输出:
968459814