题目描述
你要进行一个行程为7000KM的旅行,现在沿途有些汽车旅馆,为了安全起见,每天晚上都不开车,住在汽车旅馆,你手里现在已经有一个旅馆列表,用离起点的距离来标识,如下:
0, 990, 1010, 1970, 2030, 2940, 3060
3930, 4060, 4970, 5030, 5990, 6010, 7000
但在出发之前可能还要增加一些旅馆。
现在旅行社为了节约成本,要求每天至少行驶A公里,国家旅行社为了安全起见,要求每天最多只能行驶B公里。
你想知道一共有多少种旅行方案。
输入格式
第一行输入A,第二行输入B,第三行输入N(0≤N≤20),表示在出发之前又新增N个汽车旅馆;接下来N行,每行一个整数m,表示旅馆离起点的距离(0<m<7000)。注意:没有任意两个旅馆在同一位置。
输出格式
输出一共有多少种旅行方案。
输入输出样例
输入 #1
500
1500
0
输出 #1
64
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cstdio>
#include<math.h>
using namespace std;
int n,m,a,b;
int x[40]={0,990,1010,1970,2030,2940,3060,3930,4060,4970,5030,5990,6010,7000};
int ans[50];
int main() {
cin >> a >> b >> n ;
for(int i = 1; i <= n; i++) {
cin >> x[13+i];
}
sort(x,x+13+n);
ans[0] = 1;
for(int i = 1; i <= 13+n; i++) {
for(int j = 0; j < i; j++) {
int dis = x[i] - x[j];
if(dis <= b && dis >= a ){
ans[i] += ans[j];
}
}
}
cout << ans[n+13];
return 0;
}