static int key(W_Event *data) { if (data->y == (metaHeight-B_ADD)) return add_key(data); if (data->key == 113 || data->key == 196) { /* q or ^d */ metadone(); terminate(0); } else if (data->key == 114 || data->key == 210) { /* r or ^r */ refresh(); } else if (data->key == W_Key_Up) { choose(-1); } else if (data->key == W_Key_Down) { choose(1); } else if (data->key == '\r' || data->key == ' ') { /* enter or space */ if (chosen != -1) return chose(chosen, W_LBUTTON); } else if (data->key == 'g') { /* g, for guest */ if (chosen != -1) return chose(chosen, W_MBUTTON); } else if (data->key == 'o') { /* o, for observe */ if (chosen != -1) return chose(chosen, W_RBUTTON); } else if (data->key == 'h') { toggle_help(); } else { return button(data); } return 0; }
int main() { int caseNumber = 1; scanf("%d", &numOfCases); while(numOfCases--) { memset(dp, -1, sizeof dp); scanf("%lld %lld", &N, &K); long long array[N]; for(long long i = 0; i < N; i++) scanf("%lld", &array[i]); std::sort(array, array + sizeof(array)/sizeof(array[0])); //for(int i = 0; i < N; i++) printf("%d ", array[i]); //printf("\n"); long long num = choose(N, K); long long sum = 0; while(num--) { sum += choose(N-1, K-1); } printf("case #%d: %lld\n", caseNumber, sum); caseNumber++; return 0; } return 0; }
/** * Description not yet available. * \param */ void lvector::fill_multinomial(const int& seed, const dvector& p) // Fils a dvector with random numbers drawn from a multinomial distribution { double sum=mean(p)*p.size(); int pmin=p.indexmin(); int pmax=p.indexmax(); dvector tmp(pmin,pmax); dvector tmp1(pmin,pmax); dvector choose(indexmin(),indexmax()); choose.fill_randu(seed); tmp=p/sum; tmp1(pmin)=tmp(pmin); for (int j=pmin+1;j<=pmax-1;j++) { tmp1(j)=tmp1(j-1)+tmp(j); } tmp1(pmax)=1.0; for (int i=indexmin();i<=indexmax();i++) { int j=pmin; while (choose(i)>tmp1(j)) { j++; } (*this)(i)=j; } }
int choose(int m, int n) { if(m > n) return 0; if(m == 0) return 1; if(m == 1) return n; if(m == n) return 1; if(m == (n-1)) return n; return(choose(m,n-1)+choose(m-1, n-1)); }
long long choose(long long n, long long k) { if(dp[n][k] != -1) return dp[n][k]; if(n < k) return 0; if(n == 0) return 0; if(k == 0) return 1; if(n == k) return 1; if(1 == k) return n; else return (choose(n-1, k-1) + choose(n-1, k)); }
//computes n choose m mwSize choose(mwSize m, mwSize n) { if(m > n) return 0; if(m == 0) return 1; if(m == 1) return n; if(m == n) return 1; if(m == (n-1)) return n; return(choose(m, n-1) + choose(m-1, n-1)); }
int choose(int n, int r) { static int memo[100][100]; if(memo[n][r] != 0 ) return memo[n][r]; if(r == 0 || n ==r) return memo[n][r] = 1; else return memo[n][r] = choose(n-1, r-1) + choose(n-1, r); }
void Login_3()//教室登陆验证函数 { FILE *fp_1; FILE *fp_2; int find = 0; char Userstrcat[22] = { 0 }; char Userdata[22] = { 0 }; fp_1 = fopen("dataT.dat", "rb"); fp_2 = fopen("dataL.dat", "wb"); printf("================================================================================"); printf("\n Teacher,Please enter the information of yourself to register11\n "); /* printf(" ID :"); fflush(stdin); gets(INPUT); printf("\n"); printf(" Password :"******"%s %s", INPUT_1[IN].ID, INPUT_1[IN].Password); fwrite(&INPUT_1[IN], sizeof(struct Login_1), 1, fp_2); printf("\n Logining.........."); printf("\n Please wait.......\n"); while (!feof(fp_1)) { fread(Userdata, sizeof(struct Login_1), 1, fp_1); if (strcmp(Userstrcat, Userdata) == 0) { getchar(); printf("\n Login Successful!\n"); printf(" %s,Welcome back!\n", INPUT_1[IN].ID); find = 1; printf("==============================================================================="); printf("\n\n Enter to next "); getchar(); system("cls"); choose(); break; } } if (!find) { choose(); //printf("\n Login failed! Pleas try again!\n"); } fclose(fp_1); fclose(fp_2); }
real choose(int n, int k) { if (n <= 0) return 1; if (k <= 0) return 1; if (n < k) return n; // Recurse if n is too high if ( (fact(n) == 0.) || isinf(fact(n)) ) return choose(n-1, k-1)+choose(n-1, k); return fact(n)/(fact(k)*fact(n-k)); }
int main(void) { int n = 2, m = 3; f(&a, &b); f(&c, &d); b = choose (0, n, m); a += choose (1, n, m); a += fs163_main (10); return a; }
void choose(int d, Card card[], int n) { if(n == 5){ Card buf[5]; int tmp; memmove(buf, card, sizeof(card[0])*5); if((tmp=judge(buf)) > ans) ans = tmp; } else{ card[n] = hand[n]; choose(d, card, n+1); card[n] = deck[d]; choose(d+1, card, n+1); } }
int main(void) { char buf[5]; int i; Card card[5]; initSign(); while(scanf("%s", buf) != EOF){ ans = 0; printf("Hand: %s ", buf); insertCard(sign[buf[1]], sign[buf[0]], &hand[0]); for(i=1; i<5; i++){ scanf("%s", buf); printf("%s ", buf); insertCard(sign[buf[1]], sign[buf[0]], &hand[i]); } printf("Deck: "); for(i=0; i<5; i++){ scanf("%s", buf); printf("%s ", buf); insertCard(sign[buf[1]], sign[buf[0]], &deck[i]); } choose(0, card, 0); printf("Best hand: %s\n", name[ans]); } return 0; }
int main(void) { printf("Starting.\n"); int count = 0; int n=0; int r=0; /* printf("upper int limit %d\n", INT_MAX); */ /* printf("factorial(23) %d\n", factorial(23)); */ /* printf("choose(23, 10) %d\n", choose(23,10)); */ for(n=1; n <= N; n++) { for(r=0; r <= n; r++) { /* for(r=0; r <= n/2 + 1; r++) { */ /* printf("%d choose %d\n", n, r); */ mpz_t ans; choose(ans, n, r); gmp_printf("%d choose %d is %Zd\n", n, r, ans); if (mpz_cmp_ui(ans , 1000000) > 0) { count++; } } } printf("Answer %d\n", count); return 0; }
constraint mk_class_instance_cnstr(std::shared_ptr<class_instance_context> const & C, local_context const & ctx, expr const & m, unsigned depth) { environment const & env = C->env(); justification j = mk_failed_to_synthesize_jst(env, m); auto choice_fn = [=](expr const & meta, expr const & meta_type, substitution const &, name_generator const &) { if (auto cls_name_it = is_ext_class(C->tc(), meta_type)) { name cls_name = *cls_name_it; list<expr> const & ctx_lst = ctx.get_data(); list<expr> local_insts; if (C->use_local_instances()) local_insts = get_local_instances(C->tc(), ctx_lst, cls_name); list<name> insts = get_class_instances(env, cls_name); if (empty(local_insts) && empty(insts)) return lazy_list<constraints>(); // nothing to be done // we are always strict with placeholders associated with classes return choose(std::make_shared<class_instance_elaborator>(C, ctx, meta, meta_type, local_insts, insts, j, depth)); } else { // do nothing, type is not a class... return lazy_list<constraints>(constraints()); } }; bool owner = false; bool relax = C->m_relax; return mk_choice_cnstr(m, choice_fn, to_delay_factor(cnstr_group::Basic), owner, j, relax); }
long long int choose(int n,int k) { if(k>n) return 0; if(n<=1) return 1; if(k==0) return 1; if(nck[n][k]!=-1) return nck[n][k]; long long int answer = choose(n-1,k-1) + choose(n-1,k); answer%=MOD; nck[n][k] = answer; return answer; }
void KDTree<Dim>::buildKDTree(int dimension, int bottom, int top) { if(top == bottom) { return; //"base case" } int middle = (top+bottom)/2;//declare middle //call the "choose" helper function to sort of split this thing choose(middle, bottom, top, dimension); if(top > middle) //check upper end { //make recursive call buildKDTree((dimension+1)%Dim, middle+1, top); //call this thing on the upper end } if(bottom < middle) //check lower end { //make recursive call buildKDTree((dimension+1)%Dim, bottom, middle-1); //call this thing on the lower end } }
double dwilcox(double x, double m, double n, int give_log) { double d; #ifdef IEEE_754 /* NaNs propagated correctly */ if (ISNAN(x) || ISNAN(m) || ISNAN(n)) return(x + m + n); #endif m = R_forceint(m); n = R_forceint(n); if (m <= 0 || n <= 0) ML_ERR_return_NAN; if (fabs(x - R_forceint(x)) > 1e-7) return(R_D__0); x = R_forceint(x); if ((x < 0) || (x > m * n)) return(R_D__0); int mm = (int) m, nn = (int) n, xx = (int) x; w_init_maybe(mm, nn); d = give_log ? log(cwilcox(xx, mm, nn)) - lchoose(m + n, n) : cwilcox(xx, mm, nn) / choose(m + n, n); return(d); }
int main( int argc,char **argv ) { int arg = argc>1 ? atoi( argv[1] ) : 0; choose( arg ); return( arg ); }
static void qansari(int len, double *P, double *Q, int m, int n) { int i, l, u; double c, p, xi; double ***w; w = w_init(m, n); l = (m + 1) * (m + 1) / 4; u = l + m * n / 2; c = choose(m + n, m); for (i = 0; i < len; i++) { xi = P[i]; if(xi < 0 || xi > 1) error(_("probabilities outside [0,1] in qansari()")); if(xi == 0) Q[i] = l; else if(xi == 1) Q[i] = u; else { p = 0.; int q = 0; for(;;) { p += cansari(q, m, n, w) / c; if (p >= xi) break; q++; } Q[i] = q; } } }
int main(int argc, char **argv) { struct player_st player; struct msg_chn_list_st *chn_list = NULL; FILE *fp; /* Parse .conf */ /* Check environ */ /* while (1) { c=getopt(); } */ recv_sd = init_socket(); if (recv_sd < 0){ exit(1); } rcv_list(&chn_list); player.chn_id = choose(chn_list); free(chn_list); fp = popen(global_conf.player_cmdl,"w"); player.pipefd = fileno(fp); play_job(&player); pclose(fp); while(1){ pause(); } return 0; }
/* Attempt to solve 'board'; return 0 on success else -1 on error. * * The solution process attempts to fill-in deterministically as * much of the board as possible. Once that is no longer possible, * need to choose a square to fill in. */ static int solve( void ) { int idx; rb->yield(); while( 1 ) { if( 0 == deterministic( ) ) { /* Solved, make a new choice, or rewind a previous choice */ idx = choice( ); if( -1 == idx ) return 0; else if( ( idx < 0 || -1 == choose( idx, 1 ) ) && -1 == backtrack( ) ) return -1; } else /* rewind to a previous choice */ if( -1 == backtrack( ) ) return -1; } return -1; }
void choose(Stack *park_stack, Stack *temp_stack, Link_queue *wait_queue) { char rec[10]; printf("\t\033[40;36m请输入你的选择: \033[0m"); scanf("%s",rec); if(my_strcmp(rec,"1") == 0) //比较输入 { system("reset"); park(park_stack,temp_stack,wait_queue); //调用函数 } else if(my_strcmp(rec,"2") == 0) { system("reset"); out(park_stack,temp_stack,wait_queue); } else if(my_strcmp(rec,"3") == 0) { system("reset"); see(park_stack,temp_stack,wait_queue); } else if(my_strcmp(rec,"4") == 0) { system("reset"); printf("\n\033[40;36m感谢你使用新智停车管理系统,祝你旅途愉快!~^.^~\033[0m\n\n"); exit(0); } else { printf("\t\033[40;36m选择错误,请正确选择你要使用的功能。\033[0m\n\n"); choose(park_stack,temp_stack,wait_queue); } }
bool Downloader::setup( PluginRegistry& from,const uint32_t internalFormat, const float minQuality, const bool ignoreAlpha, const uint64_t capabilities,const GLEWContext* gl) { return impl_->setup( from, choose( from, internalFormat, minQuality, ignoreAlpha, capabilities, gl ), gl ); }
/* * stm is top of template. Create a new parse-tree and copy to it. */ static int traverse(struct xml_node *st, struct xml_node *xt, struct xml_node *rtop) { struct xml_node *rt; int i; if (st->xn_namespace && strcmp(st->xn_namespace, "xsl") == 0){ /* do intelligent stuff */ if (strcmp(st->xn_name, "value-of")==0) value_of(st, xt, rtop); else if (strcmp(st->xn_name, "for-each")==0) for_each(st, xt, rtop); else if (strcmp(st->xn_name, "if")==0) ifelement(st, xt, rtop); else if (strcmp(st->xn_name, "choose")==0) choose(st, xt, rtop); } else{ /* just copy */ if ((rt = xml_new(st->xn_name, rtop)) == NULL) return -1; xml_cp1(st, rt); for (i=0; i<st->xn_nrchildren; i++) if (traverse(st->xn_children[i], xt, rt) < 0) return -1; } return 0; }
int get_description (char *string, int *len, int **seq, struct pcp_vars *pcp) { char *name; FILE *file; name = GetString (string); file = OpenFile (name, "r"); if (file == NULL) { if (isatty (0)) return FALSE; else exit (FAILURE); } restore_pcp (file, pcp); CloseFile (file); /* length of sequence */ *len = choose (pcp->lastg + 1, 3); /* sequence of exponents */ *seq = compact_description (FALSE, pcp); return TRUE; }
int main() { for (int i=1; i<=20; i++) { printf("%d: %ld\n", i, choose(i*2, i)); } return 0; }
/* enumerate all subsets of a certain size (R interface). */ SEXP r_subsets(SEXP elems, SEXP size) { int i = 0, k = 0, n = length(elems), r = INT(size), *id = NULL; double nsub = choose(n, r); SEXP result; if (nsub * r > INT_MAX) error("too many subsets of size %d.", r); /* allocate the scratch space and the return value. */ id = Calloc(r, int); PROTECT(result = allocMatrix(STRSXP, nsub, r)); /* iterate over subsets. */ first_subset(id, r, 0); for (k = 0; k < nsub; k++) { for (i = 0; i < r; i++) SET_STRING_ELT(result, CMC(k, i, nsub), STRING_ELT(elems, id[i])); next_subset(id, r, n, 0); }/*FOR*/ Free(id); UNPROTECT(1); return result; }/*R_SUBSETS*/
PoleView::PoleView(): QMainWindow() { storage = 0; view = new QListView( this ); view->addColumn( tr("Name" ) ); view->addColumn( tr("Size" ) ); view->setColumnAlignment( 1, Qt::AlignRight ); setCentralWidget( view ); QPopupMenu * file = new QPopupMenu( this ); menuBar()->insertItem( tr("&File"), file ); file->insertItem( tr("&New Window"), this, SLOT(newWindow()), CTRL+Key_N ); file->insertItem( tr("&Open..."), this, SLOT(choose()), CTRL+Key_O ); file->insertItem( tr("&Close"), this, SLOT(closeFile()) ); file->insertSeparator(); file->insertItem( tr("&Quit"), qApp, SLOT( closeAllWindows() ), CTRL+Key_Q ); QPopupMenu * streamMenu = new QPopupMenu( this ); menuBar()->insertItem( tr("&Stream"), streamMenu ); streamMenu->insertItem( tr("&Export..."), this, SLOT(exportStream() ), CTRL+Key_E ); streamMenu->insertItem( tr("&View..."), this, SLOT(viewStream()) ); QPopupMenu * help = new QPopupMenu( this ); menuBar()->insertItem( tr("&Help"), help ); help->insertItem( tr("&About"), this, SLOT(about()), Key_F1 ); help->insertItem( tr("About &Qt"), this, SLOT(aboutQt()) ); resize( 400, 300 ); setCaption( tr("POLEView" ) ); statusBar()->message( tr("Ready"), 5000 ); }
void CompareListExpression::notify() { size_t i,j,sz; sz=d_->args_->size(); if(sz==0) { d_->choice_=d_->null_; return; } else if(sz==1) { d_->choice_=d_->args_->at(0); d_->choice_->notify(); return; } for( i=0, j=1; j<sz; ++i, ++j ) { ExpressionPtr lhs=d_->args_->at(i); ExpressionPtr rhs=d_->args_->at(j); lhs->notify(); rhs->notify(); d_->choice_=choose(lhs, rhs); } }
main(){ unsigned long long int n, m, ans; scanf("%llu%llu",&n,&m); ans = choose(n,m); printf("%llu\n",ans); system("pause"); return 0; }