Xidianoj 1095 Party

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.