int cal_delta(int h,int alpha,int beta)    //calculate the delta of inter_polynomial, c is inter_poly[i] and t is tk
{
	int delta=0,delta_temp=0,i,j,flag;
	int a,b,x,y;

	x=inter_point[0];			//xi=pi
	y=inter_point[1];			//yi=ri

	for(j=0;j<poly_Ysize; j++)
	{
		for(i=0;i<poly_Xsize;i++)
		{
			if( (inter_poly[h][j][i] != 0)  && (j>=beta) && (i>=alpha) )
			{
				a=i;
				b=j;
				flag= ((int)comb(a,alpha)) * ((int)comb(b,beta));
				// if flag is even number , delta_temp is equal to 0
				// if flag is odd number, delta_temp can be calculated to the delta
				if( (flag%2) !=0 )
				{
					delta_temp=mul(inter_poly[h][j][i],power(x,(a-alpha)));
					delta_temp=mul(delta_temp,power(y,(b-beta)));
					delta= add(delta,delta_temp);
				}
			}
		}	
	}

	return delta;
}
void comb(int s, int n, int m)
{
    int i;

    if (s >= n || flag==1)
        return ;

    if (top == m)
    {

        if (flag==queue[m-2] && m>1)
            return ;

        for (i = 0; i < m; i++)
        {
            printf("%d", queue[i]);
            ss = ss + e0[queue[i]] ;
        }
        printf("\t");
        if( (1-sigma/temperature * (ss + (NPARTICLE - m) * e0[0])) > 0)
        {
        // for (i = 0; i < m; i++)
        // {
        //     printf("%d", queue[i]);
        // }
        // printf("\t");
            partition[q-1] = partition[q-1] + pow((1-sigma/temperature * (ss + (NPARTICLE - m) * e0[0])),1/sigma);
            ppartition[q-1] = ppartition[q-1] + pow((1-sigma/temperature * (ss + (NPARTICLE - m) * e0[0])),1/sigma+1);
        // printf("(1-sigma/temperature*(ss+(NPARTICLE-m)*e0[0])^(1/sigma)=");
        printf("%2.2e",pow((1-sigma/temperature * (ss + (NPARTICLE - m) * e0[0])),1/sigma) );
        printf("\t");
        printf("%2.2e\n",(1-sigma/temperature * (ss + (NPARTICLE - m) * e0[0])) );
            flag=queue[m-2];
        flag=0;
        }
        else
        {
            // goto jump;
            partition[q-1] = partition[q-1] + 0.0;
            ppartition[q-1] = ppartition[q-1] + 0.0;
        printf("\t");
        printf("\t");
        printf("%2.2e\n",(1-sigma/temperature * (ss + (NPARTICLE - m) * e0[0])) );
            flag=1;
        }
        sum=sum+1;
        ss = 0.0;
        return ;
    }

    queue[top++] = array[s];

    // if (flag==queue[m-2])
    //     return ;

    comb(s, n, m);
    top--;
    comb(s+1, n, m);

}
int comb(int n,int r)
{
	if(r==0||r==n)
	    return 1;
	else
	return comb(n-1,r-1)+comb(n-1,r);
}
示例#4
0
int main()
{
	int monsters;
	int skills;
	printf("How many monsters do you have?: " );
	scanf("%i", &monsters);
	printf("How many skillups do you want?: ");
	scanf("%i", &skills);

	long long combinations = comb(monsters, skills);
	
//	printf("Done with comb");
	long double answer = 0;
	for(int i = skills; i <= monsters; i++)
	{
		answer += noSkill(monsters - i) * yesSkill(i) * comb(monsters, i);	
		printf("%Lf answer\n", answer);
	}
	answer *= 100;
		
//	double answer = noSkill*yesSkill*combinations*100;
	//printf("%f noSkill\n", noSkill);
	//printf("%f yesSkill\n", yesSkill);
	
	printf("You have a %Lf%% chance to get at least  %i skillups out of %i monsters\n", answer, skills, monsters);

	return -1;
}
void comb(int s, int n, int m)
{
    int i;

    if (s >= n)
        return ;

    if (top == m)
    {
        for (i = 0; i < m; i++)
        {
            printf("%d", queue[i]);
            // ss = ss + queue[i] ;
        }
            // printf("%d", ss);
        printf("\t");
        sum=sum+1;
        ss = 0.0;
        return ;
    }

    queue[top++] = array[s];
    comb(s, n, m);
    top--;
    comb(s+1, n, m);
}
//===========================
int main(void) {
	setvbuf(stdout, NULL, _IONBF, 0);
	FILE *outPutFile; 
	int n;
	int r;
	char buffer[BUFSIZ+1];
	 outPutFile = fopen("comb.txt", "w");
	puts("Combinatorials"); /* prints !!!Hello World!!! */
	n = 0;
	r = 0;
	do{
		printf("Enter value one:");
		fprintf(outPutFile, "Enter value one:");
		n = atoi(gets(buffer));
		fprintf(outPutFile,"%d", n);
		//printf("\n");
		printf("Enter value two:");
		fprintf(outPutFile, "Enter value two:");
		r = atoi(gets(buffer));
		fprintf(outPutFile,"%d", r);
		//printf("\n");
		if(check(n, r)){
			printf("comb %d\n", comb(n, r));
			fprintf(outPutFile,"comb %d\n", comb(n, r));
		}
	}while((r > 0)&&( n > 0));
	
	
	return EXIT_SUCCESS;
}
示例#7
0
int comb(int a, int n)
{
    if(a == 0) return 1;
    if(a < 0) return 0;
    if(n == 0) return 0;
    
    return comb(a, n - 1) + comb(a - coins[NUM - n][1], n);
}
示例#8
0
long long comb(int i, int j)
{
	if(i<0||j<0) return 1;
	if(Comb[i][j])
		return Comb[i][j];
	if(!i||!j||i==j)
		return Comb[i][j]=1;
	return Comb[i][j]=comb(i-1,j)+comb(i-1,j-1);
}
示例#9
0
文件: combination.c 项目: kw-udon/ucc
int comb (int a, int b) {
  if (dp[a][b] != 0)
    return dp[a][b];
  if (a < b)
    return -1;
  if (a == b || b == 0) {
    dp[a][b] = 1;
  } else {
    dp[a][b] = comb(a-1, b-1) + comb(a-1, b);
  }
  return dp[a][b];
}
示例#10
0
文件: spoon.c 项目: abhisheknith/Code
unsigned long long int comb(int n,int k)
{
        if(arr[n][k])
        {
                return arr[n][k];
        }
        if(k==1  || n-k==1)
                return n;
        if(n==k)
                return 1;
        return (arr[n][k]=comb(n-1,k-1)+comb(n-1,k));
}
示例#11
0
//setter
void Curve::setCurve(vector<Point> points) {
	table.clear();
	int n = points.size();
 	int x, y, u;
  	for (float i=0;i<1;i+=0.0001) {
    	x = 0; y = 0;
    	for (u=0;u<n;u++) {
      		x += comb(n-1,u)*pow(i,u)*pow(1-i,n-1-u)*points[u].getAbsis();
      		y += comb(n-1,u)*pow(i,u)*pow(1-i,n-1-u)*points[u].getOrdinat();
    	}
    	table.push_back(Point(x,y));
  	}
}
示例#12
0
//constructor param
Curve::Curve(vector<Point> points) {
	int n = points.size();
	int x1, y1, u;
 	float x, y;
  	for (float i=0;i<1;i+=0.01) {
    	x = 0; y = 0;
    	for (u=0;u<n;u++) {
      		x += comb(n-1,u)*pow(i,u)*pow(1-i,n-1-u)*points[u].getAbsis();
      		y += comb(n-1,u)*pow(i,u)*pow(1-i,n-1-u)*points[u].getOrdinat();
    	}
    	x1 = (int)x;
    	y1 = (int)y;
    	table.push_back(Point(x1,y1));
  	}
}
示例#13
0
void comb(int pool, int need, marker chosen, int at)
{
	if (pool < need + at) return; /* not enough bits left */
 
	if (!need) {
		/* got all we needed; print the thing.  if other actions are
		 * desired, we could have passed in a callback function. */
		for (at = 0; at < pool; at++)
			if (chosen & (one << at)) combs = combs + 1;
		return;
	}
	/* if we choose the current item, "or" (|) the bit to mark it so. */
	comb(pool, need - 1, chosen | (one << at), at + 1);
	comb(pool, need, chosen, at + 1);  /* or don't choose it, go to next */
}
示例#14
0
void main() {
	IplImage* img;
	CvCapture* cap=cvCaptureFromCAM(0);
	cvNamedWindow("Line Counter", 1);
	CvFont* font1=new CvFont;
	CvFont* font2=new CvFont;
	cvInitFont(font1, CV_FONT_HERSHEY_SIMPLEX, 0.5f, 1.0f, 0, 3, 8);
	cvInitFont(font2, CV_FONT_HERSHEY_SIMPLEX, 0.5f, 1.0f, 0, 2, 8);
	int val=0, axx=0, bxx=0;
	char text[8];
	for (;;) {
		img = cvQueryFrame(cap);
		if (!img) break;
		IplImage* gray1=cvCreateImage(cvSize(img->width, img->height), 8, 1);
		IplImage* edge1=cvCreateImage(cvSize(img->width, 16), 8, 1);
		cvCvtColor(img, gray1, 7);
		extract(gray1, edge1);
		dy(edge1, edge1);
		cvThreshold(edge1, edge1, 10, 255, CV_THRESH_BINARY_INV);
		val=count(edge1);
		if (val==0&&axx==0) { axx=1; }
		if (val==2&&axx==1) { axx=0; bxx++; }
		sprintf(text, "%i", bxx);
		comb(gray1, edge1);
		cvPutText(gray1, text, cvPoint(10, 160), font1, cvScalarAll(255));
		cvPutText(gray1, text, cvPoint(10, 160), font2, cvScalarAll(0));
		cvShowImage("Line Counter", gray1);
		if (cvWaitKey(5) > 0) break;
		cvReleaseImage(&gray1);
		cvReleaseImage(&edge1);
	}
}
示例#15
0
int main(void) {
	int Nj = 4;
	
	unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
	std::mt19937_64 gen(seed);
	std::uniform_real_distribution<float> dis(0, 1);
	
	std::vector<float> v;
	for(int i = 0; i < Nj; ++i) v.push_back(dis(gen));
	
	std::cout << "individual probabilities:" << std::endl;
	for(auto val: v) std::cout << std::fixed << val << "\t";
	std::cout << std::endl << std::endl;
	
	float sum = 0.0;
	for(int Ntag = 0; Ntag <= Nj; ++Ntag) {
		std::cout << "combined probabilities:" << std::endl;
		float combi = comb(v, Nj, Ntag);
		std::cout << std::endl << "the sum of combined probability:\t";
		std::cout << combi << std::endl;
		sum += combi;
	}
	
	std::cout << std::endl << "overall sum of probabilities:\t" << sum << std::endl;
	
	return EXIT_SUCCESS;
}
 int gen(int m, int n, pair<int, int>& p, unordered_map<string, vector<string>>& source, unordered_map<string, string>& refer) {
     string pos = to_string(p.first) + "#" + to_string(p.second);
     refer[pos] = pos;
     source[pos] = vector<string>(1, pos);
     
     vector<string> List;
     if (p.first > 0) {
         string tempPos = to_string(p.first-1) + "#" + to_string(p.second);
         List.push_back(tempPos);
     }
     if (p.first < m-1) {
         string tempPos = to_string(p.first+1) + "#" + to_string(p.second);
         List.push_back(tempPos);
     }
     if (p.second > 0) {
         string tempPos = to_string(p.first) + "#" + to_string(p.second-1);
         List.push_back(tempPos);
     }
     if (p.second < n-1) {
         string tempPos = to_string(p.first) + "#" + to_string(p.second+1);
         List.push_back(tempPos);
     }
     for (string l : List) comb(source, refer, l, pos);
     
     return source.size();
 }
示例#17
0
 vector<vector<int> > combinationSum2(vector<int> &num, int target) {
     vector<vector<int> > ret;
     vector<int> temp;
     sort(num.begin() , num.end());
     comb(ret , temp , num , 0 , target);
     return ret;
 }
示例#18
0
int main()
{
    printf("k=%d", comb(100, 5));
    //int n = 0;
    //printf("%d", coins[NUM - (n)][1]);
    return 0;
}
nBinEqvCod::nBinEqvCod(int n, int w, int q) : n(n), w(w), q(q)
{
    omp_set_dynamic(1);
    omp_set_num_threads(8);
    mpz_ui_pow_ui(qw.get_mpz_t(), (q - 1), w);
    //qw = qPow((q - 1), w);
	//qw = Bigint(q-1).pow(w);

	M = mpz_class(qw) * comb(n, w); // factorial(n) / (factorial(w) * factorial(n - w));

    //code = new nBinEqvVec[M];
    code = nullptr;

	qDebug() << "Creating non_binary equivalent codes";
	qDebug() << "n:" << n << "\tw: " << w << "\tq:" << q << "\tM: " << M.get_str().c_str();

	//#pragma omp parallel for
	//for (int i = 0; i < M; ++i)
	//{
	//	calc_eVec(i, &code[i]);
	//	mapNBEV.insert(code[i].Ca, &code[i]);
	//}
	//--------------------------------------------------
	//QTime midnight(0, 0, 0);
	//qsrand(midnight.secsTo(QTime::currentTime()));
	//code = new nBinEqvVec[3];
	//calc_eVec(qrand() % M, code[0]);
	//calc_eVec(qrand() % M, code[1]);
	//calc_eVec(qrand() % M, code[2]);
}
int judge(int m, int l)                 // m=particles number on the excited state, l=data point
{
    int i,j;                             // loop index
    int lmax;                            // maximum energy level


    for (j=1; j<MAXIMUM_ENERGY; j++)
    {
        if((1 - ( (PARTICLE_NUMBER - m) * e0[0] + (m-1) * e0[1] + e0[j])/(temperature[l]*N3))< 0)
        {
            lmax = j - 1;
            printf("%d\n", lmax);
            printf("%4.2e\n", (1 - ( (PARTICLE_NUMBER - m) * e0[0] + (m-1) * e0[1] + e0[j-1])/(temperature[l]*N3)));
            break;
        }
        else
        {
            lmax = j;
        }
    }

    if (lmax==0)
    {
        return 0;
    }
    else
    {
        comb(lmax, m, l);
        return 1;
    }
}
示例#21
0
int main()
{
	long int a,b,total;
	scanf("%ld %ld",&a,&b);
	total=comb(a,b,1,1);
	printf("%ld\n",total);
	return 0;
}
示例#22
0
int main()
{
	int i = 0;
	int a[4] = {1,2,3,4};
	perm(a,0,4);
	for(i = 1; i <= 4;i++)
	comb(a, 4, i);
}
示例#23
0
 vector<vector<int> > combinationSum(vector<int> &candidates, int target) {
     vector<vector<int> > ret;
     vector<int> sol;
     sort(candidates.begin(),candidates.end());
     int sum=0;
     comb(ret,sol,candidates,sum,target,0);
     return ret;
 }
示例#24
0
 vector<vector<int> > combinationSum2(vector<int> &num, int target) {
     vector<vector<int> > ret;
     vector<int> sol;
     sort(num.begin(),num.end());
     int sum=0;
     comb(ret,sol,num,sum,target,0);
     return ret;
 }
int main(void)
{
	int list[] = {'A','B', 'c'};
	int list_size = sizeof(list) / sizeof(int);

	comb (list, list_size, 0);

	return 0;
}
    vector<vector<int>> combine(int n, int k)
    {
        vector<vector<int> > ans;
        vector<int> path;
        comb(n,k,ans,path);

        return ans;
        
    }
示例#27
0
int main()
{
	while(scanf("%d%d",&n,&k))
	{
		if(!n&&!k) break;
		printf("%d things taken %d at a time is %I64d exactly.\n",n,k,comb(n,k));
	}
	return 0;
}
示例#28
0
文件: comb.c 项目: jilikuang/practice
int main(int argc, char **argv)
{
	int n = strtol(argv[1], NULL, 0);
	int k = strtol(argv[2], NULL, 0);

	printf("%d\n", comb(n, k));

	return 0;
}
int main()
{
    int i, j, p;
    int lmax=0;

    for (i=0; i<NUM; i++)
    {
        array[i] = i + 1;
        e0[i]=0.0845032*k[i]*k[i];
    }

    for ( i=0; i<T; i++)
    {
        partition[i] =  0.0;
        ppartition[i] = 0.0;
    }

    q = 0;
    for (i=0; i<T; i++)
    {
        q = q + 1;
        temperature = tmin + tem * q / T;
        partition[i] =  pow(( 1-sigma*NPARTICLE*e0[0]/temperature ),1/sigma);
        ppartition[i] = pow(( 1-sigma*NPARTICLE*e0[0]/temperature ),1/sigma+1);
        printf("partition(%2.4f)=",temperature);
        printf("%5.5e\n", partition[i]);
        for (j=1; j<NPARTICLE+1; j++)
        {
            flag = 0;
            for (p=1; p<NUM; p++)
            {
                if((1-sigma*((NPARTICLE - j)*e0[0] + (j-1) * e0[1] + e0[p])/temperature) < 0)
                {
                    lmax = p-1 ;
                    // printf("%d\n", lmax);
                    // printf("%5.8f\n", (1-sigma*((NPARTICLE - j)*e0[0] + (j-1) * e0[1] + e0[p-1])/temperature));
                    break;
                }
                else
                    lmax = p;
            }
            if (lmax==0)
                break;
            else
                comb(0, lmax, j, 0);
        printf("partition(%2.4f)=",temperature);
        printf("%5.5e\n", partition[i]);
        }
        printf("partition(%2.4f)=",temperature);
        printf("%5.5e\n", partition[i]);
    }



    return 0;
}
示例#30
0
文件: alglib.hpp 项目: jasy/alglib
std::vector<std::vector<U>> Cs(T n)
{
    std::vector<std::vector<U>> comb(n+1,std::vector<U>(n+1,0));
    for(T i=0; i<=n; ++i)
    {
        comb[i][0]=1;
        for(T j=1; j<=i; ++j) comb[i][j]=comb[i-1][j]+comb[i-1][j-1];
    }
    return comb;
}