Title Description
Matrix67 found that people who were close to each other seemed more fit. MATRIX67 Party A total of N (1<=n<=10) individual participation, Matrix67 need to put them on the round table. The Matrix67 arrangement principle is that the difference in height of any two adjacent persons on the table cannot exceed K. Please tell Matrix67 how many kinds of arrangements he has in common.
Enter multiple sets of data enter the first line two spaces separated by the number N and K, where 1<=n<=10,1<=k<=1 000 000.
The second line to line n+1 Enter a person's height value per line. The height of all people is not more than 1 000 000 positive integer
Output
Total number of outputs that meet the requirements
--Body n is very small, just try it one by one.
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;intheight[ One];intvisit[ One];inttable[ One];intn,k;intres =0;intMy_abs (inta) { if(a<0)return-A; returnA;}BOOLCanpos (intIintheight) { if(i = =1)return true; if(i = =N) { if(My_abs (height-table[i-1]) <= k && My_abs (height-table[1]) <=k) { return true; } Else return false; } Else if(My_abs (height-table[i-1]) <=k) { return true; } Else return false;}voidPosintNow ) { inti; if(now = = n+1) {//For (i=1;i<=n;i++) {//printf ("%d", Table[i]);//} printf ("\ n");Res++; return; } for(i=1; i<=n;i++){//if (now==1 && table[1] = +) {//printf ("here!\n");// }//if (table[1] = = && table[2] = = 6 && table[3] = = 2) {//printf ("here!\n");// } if(!visit[i] &&Canpos (Now,height[i])) {Table[now]=Height[i]; Visit[i]=1; POS ( Now+1); Table[now]=0; Visit[i]=0; } }}intMain () { while(SCANF ("%d%d", &n,&k)! =EOF) { inti; Res=0; memset (Visit,0,sizeof(visit)); memset (table,0,sizeof(table)); for(i=1; i<=n;i++) scanf ("%d",&Height[i]); POS (1); printf ("%d\n", res/N); } return 0;}
Xidianoj 1095 Party