topic:
D (1973): Give Yourself a quiz on the small xSubmit Page Summary time limit:1 Sec Memory limit:128 Mb submitted:38 solved:9
Description
Small x Learning Dfs, in order to practice the search, began to play their own topic.
Play play, one will put himself stumped, a will be baffled by their own, really interesting ah.
Small x out of the problem:
Now there are n different positive integers, asking how many such sets they can compose, satisfying: the number of elements within the collection s>1 the absolute value of the difference of any two number within the set is greater than the number of elements within the collection. Input
The first line, a positive integer T (t<=20), represents the number of data groups.
For each set of data, there are two lines. The first behavior is a positive integer n (3≤n≤25), and the second behavior is n a positive integer, separated by a space, Xi (xi≤200). Output
For each set of data, output an integer representing the number of sets described in the question. Sample Input
1
5
2 3 5 8 1
Sample Output
6
Hint
{5,8},{1,5},{1,8},{2,5},{2,8},{3,8}. The way to solve problems (copy and paste version): The number of elements in the collection can be enumerated from the 2nd, and after the number of elements has been determined, DFS searches for the number of numbers and the number of numbers in the DFS process is guaranteed to be valid.
In addition, it is also possible to not enumerate the number of elements in the collection, direct DFS to enumerate the number of I, and when determining whether the next number is legitimate, you need to check whether the current minimum adjacent interval is greater than the number of elements in the current collection. This process is best to record and pass a minimum adjacent interval at DFS time.
Code:
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include < string> #include <vector> #include <stack> #include <bitset> #include <cstdlib> #include <
cmath> #include <set> #include <list> #include <deque> #include <map> #include <queue>
using namespace Std;
typedef long Long LL;
Const double PI = ACOs (-1.0);
Const double EPS = 1e-6;
const int INF = 100000;
const int MAXN = 33;
int A[MAXN];
int t,n,m;
ll ans;
void Dfs (int num,int pos,int pre,int min_dif) {if (num>1&&min_dif>num) {ans++;
printf ("num:%d pos:%d pre:%d ans:%d\n", Num,pos,pre,ans);
} if (pos==n) return; for (int i=pos;i<n;i++) {if (a[i]-pre>num+1) {DFS (num+1,i+1,a[i],min MIN_DIF,A[I]-PR
e));
int main () {scanf ("%d", &t);
while (t--) {scanf ("%d", &n);
for (int i=0;i<n;i++) {scanf ("%d", &a[i]);
} ans=0;
Sort (a,a+n);
DFS (0,0,-inf,inf);
printf ("%lld\n", ans);
return 0; }/********************************************************************** problem:1973 user:201601090128 Language:
C + + Result:ac time:296 ms memory:2020 KB **********************************************************************/