寒假的时候做了一些搜索题,顺便就把这题做了,回学校一交就AC了
#include <iostream>
using namespace std;
const int maxn = 1000+10;
int n, m, l;
int book[maxn], damage[maxn], ci[maxn], ans = 0x3f3f3f3f;
bool isend[maxn], isgo;
void dfs( int cur, int sum ) {
if ( cur > ans ) return; //如果出剑次数比现有的最佳答案还要大那就是无意义的
if ( isend[cur] ) ans = min(ans, sum+1); //如果能够终结这条龙那么更新答案
else if ( sum <= ans ) {
for ( int i = 0; i < m; i++ ) {
if ( cur < ci[i] ) continue;
int next = cur - damage[i];
if ( next > l ) next = l;
if ( book[next] ) continue;
book[next] = true;
dfs( next, sum + 1 );
book[next] = false;
}
}
}
int main() {
int t1, t2;
cin >> n >> m >> l;
for ( int i