int main () { try1(); try2(); try3(); test(); getchar(); return 0; }
main() { int i; scanf("%d",&t); for(i=1;i<=t;i++) { scanf("%d %d",&m,&n); total=0; try1(m,1); printf("%d\n",total); } }
int main() { uint32_t x = 0; do { uint32_t r1 = ref(x); uint32_t r2 = try1(x); if (r1 != r2) { printf("FAIL: %x -> %x %x\n", x, r1, r2); exit(1); } if (x == 0xffffffff) break; x++; } while (1); return 0; }
void try1(int x,int y) { int i; if (x==0) { if (y-1<=n) total++; } else { for(i=1;i<=x;i++) { if (i>=a[y-1]) { a[y]=i; try1(x-i,y+1); a[y]=0; } } } }
/* Return "RCS" if FILENAME is controlled by RCS, "SCCS" if it is controlled by SCCS, "ClearCase" if it is controlled by Clearcase, "Perforce" if it is controlled by Perforce, and 0 otherwise. READONLY is true if we desire only readonly access to FILENAME. FILESTAT describes FILENAME's status or is 0 if FILENAME does not exist. If successful and if GETBUF is nonzero, set *GETBUF to a command that gets the file; similarly for DIFFBUF and a command to diff the file (but set *DIFFBUF to 0 if the diff operation is meaningless). *GETBUF and *DIFFBUF must be freed by the caller. */ char const * version_controller (char const *filename, bool readonly, struct stat const *filestat, char **getbuf, char **diffbuf) { struct stat cstat; char *dir = dir_name (filename); char *filebase = base_name (filename); char const *dotslash = *filename == '-' ? "./" : ""; size_t dirlen = strlen (dir) + 1; size_t maxfixlen = sizeof "SCCS/" - 1 + sizeof SCCSPREFIX - 1; size_t maxtrysize = dirlen + strlen (filebase) + maxfixlen + 1; size_t quotelen = quote_system_arg (0, dir) + quote_system_arg (0, filebase); size_t maxgetsize = sizeof CLEARTOOL_CO + quotelen + maxfixlen; size_t maxdiffsize = (sizeof SCCSDIFF1 + sizeof SCCSDIFF2 + sizeof DEV_NULL - 1 + 2 * quotelen + maxfixlen); char *trybuf = xmalloc (maxtrysize); char const *r = 0; sprintf (trybuf, "%s/", dir); #define try1(f,a1) (sprintf (trybuf + dirlen, f, a1), stat (trybuf, &cstat) == 0) #define try2(f,a1,a2) (sprintf (trybuf + dirlen, f, a1,a2), stat (trybuf, &cstat) == 0) /* Check that RCS file is not working file. Some hosts don't report file name length errors. */ if ((try2 ("RCS/%s%s", filebase, RCSSUFFIX) || try1 ("RCS/%s", filebase) || try2 ("%s%s", filebase, RCSSUFFIX)) && ! (filestat && filestat->st_dev == cstat.st_dev && filestat->st_ino == cstat.st_ino)) { if (getbuf) { char *p = *getbuf = xmalloc (maxgetsize); sprintf (p, readonly ? CHECKOUT : CHECKOUT_LOCKED, dotslash); p += strlen (p); p += quote_system_arg (p, filename); *p = '\0'; } if (diffbuf) { char *p = *diffbuf = xmalloc (maxdiffsize); sprintf (p, RCSDIFF1, dotslash); p += strlen (p); p += quote_system_arg (p, filename); *p++ = '>'; strcpy (p, DEV_NULL); } r = "RCS"; } else if (try2 ("SCCS/%s%s", SCCSPREFIX, filebase) || try2 ("%s%s", SCCSPREFIX, filebase)) { if (getbuf) { char *p = *getbuf = xmalloc (maxgetsize); sprintf (p, readonly ? GET : GET_LOCKED); p += strlen (p); p += quote_system_arg (p, trybuf); *p = '\0'; } if (diffbuf) { char *p = *diffbuf = xmalloc (maxdiffsize); strcpy (p, SCCSDIFF1); p += sizeof SCCSDIFF1 - 1; p += quote_system_arg (p, trybuf); sprintf (p, SCCSDIFF2, dotslash); p += strlen (p); p += quote_system_arg (p, filename); *p++ = '>'; strcpy (p, DEV_NULL); } r = "SCCS"; } else if (!readonly && filestat && try1 ("%s@@", filebase) && S_ISDIR (cstat.st_mode)) { if (getbuf) { char *p = *getbuf = xmalloc (maxgetsize); strcpy (p, CLEARTOOL_CO); p += sizeof CLEARTOOL_CO - 1; p += quote_system_arg (p, filename); *p = '\0'; } if (diffbuf) *diffbuf = 0; r = "ClearCase"; } else if (!readonly && filestat && (getenv("P4PORT") || getenv("P4USER") || getenv("P4CONFIG"))) { if (getbuf) { char *p = *getbuf = xmalloc (maxgetsize); strcpy (p, PERFORCE_CO); p += sizeof PERFORCE_CO - 1; p += quote_system_arg (p, filename); *p = '\0'; } if (diffbuf) *diffbuf = 0; r = "Perforce"; } free (trybuf); free (filebase); free (dir); return r; }
/* Return "RCS" if FILENAME is controlled by RCS, "SCCS" if it is controlled by SCCS, "ClearCase" if it is controlled by Clearcase, and 0 otherwise. READONLY is nonzero if we desire only readonly access to FILENAME. FILESTAT describes FILENAME's status or is 0 if FILENAME does not exist. If successful and if GETBUF is nonzero, set *GETBUF to a command that gets the file; similarly for DIFFBUF and a command to diff the file (but set *DIFFBUF to 0 if the diff operation is meaningless). *GETBUF and *DIFFBUF must be freed by the caller. */ char const * version_controller (char const *filename, int readonly, struct stat const *filestat, char **getbuf, char **diffbuf) { #define BK_STAT "bk _stat " struct stat cstat; char const *filebase = base_name (filename); char const *dotslash = *filename == '-' ? "./" : ""; size_t dir_len = filebase - filename; size_t filenamelen = strlen (filename); size_t maxfixlen = sizeof "SCCS/" - 1 + sizeof SCCSPREFIX - 1; size_t maxtrysize = filenamelen + maxfixlen + 1; size_t maxstatsize = maxtrysize + sizeof(BK_STAT " > " NULL_DEVICE); size_t quotelen = quote_system_arg (0, filename); size_t maxgetsize = sizeof CLEARTOOL_CO + quotelen + maxfixlen; size_t maxdiffsize = (sizeof SCCSDIFF1 + sizeof DEV_NULL - 1 + 2 * quotelen + maxfixlen); char *trybuf = xmalloc (maxtrysize); char *trystat = xmalloc (maxstatsize); char const *r = 0; strcpy (trybuf, filename); sprintf(trystat, "bk _stat %s", filename); #define try1(f,a1) (sprintf (trybuf + dir_len, f, a1), stat (trybuf, &cstat) == 0) #define try2(f,a1,a2) (sprintf (trybuf + dir_len, f, a1,a2), stat (trybuf, &cstat) == 0) #define try3(f,a1,a2) (sprintf (trystat + dir_len + sizeof(BK_STAT)-1, f, a1, a2), systemic(trystat) == 0) /* Check that RCS file is not working file. Some hosts don't report file name length errors. */ if ((try2 ("RCS/%s%s", filebase, RCSSUFFIX) || try1 ("RCS/%s", filebase) || try2 ("%s%s", filebase, RCSSUFFIX)) && ! (filestat && filestat->st_dev == cstat.st_dev && filestat->st_ino == cstat.st_ino)) { if (getbuf) { char *p = *getbuf = xmalloc (maxgetsize); sprintf (p, readonly ? CHECKOUT : CHECKOUT_LOCKED, dotslash); p += strlen (p); p += quote_system_arg (p, filename); *p = '\0'; } if (diffbuf) { char *p = *diffbuf = xmalloc (maxdiffsize); sprintf (p, RCSDIFF1, dotslash); p += strlen (p); p += quote_system_arg (p, filename); *p++ = '>'; strcpy (p, DEV_NULL); } r = "RCS"; } else if (try2 ("SCCS/%s%s", SCCSPREFIX, filebase) || try2 ("%s%s", SCCSPREFIX, filebase) || try3("SCCS/%s%s > " NULL_DEVICE, SCCSPREFIX, filebase)) { if (getbuf) { char *p = *getbuf = xmalloc (maxgetsize); sprintf (p, readonly ? GET : GET_LOCKED); p += strlen (p); p += quote_system_arg (p, filename); *p = '\0'; } if (diffbuf) { char *p = *diffbuf = xmalloc (maxdiffsize); strcpy (p, SCCSDIFF1); p += sizeof SCCSDIFF1 - 1; p += quote_system_arg (p, filename); *p++ = '>'; strcpy (p, DEV_NULL); } r = "SCCS"; } else if (!readonly && filestat && try1 ("%s@@", filebase) && S_ISDIR (cstat.st_mode)) { if (getbuf) { char *p = *getbuf = xmalloc (maxgetsize); strcpy (p, CLEARTOOL_CO); p += sizeof CLEARTOOL_CO - 1; p += quote_system_arg (p, filename); *p = '\0'; } if (diffbuf) *diffbuf = 0; r = "ClearCase"; } free (trybuf); return r; }