Exemplo n.º 1
0
void combi(bool val[MAX], int curr_combi[9], int limit_use, int limit_range, int curr_arg, int curr_uses, int sum){

  if(limit_use == curr_uses || limit_range+1 == curr_arg){
    val[sum] = true;
    return;
  }

  combi(val,curr_combi,limit_use,limit_range,curr_arg,curr_uses+1,sum+curr_combi[curr_arg]);
  combi(val,curr_combi,limit_use,limit_range,curr_arg+1,curr_uses+1,sum+curr_combi[curr_arg]);
  combi(val,curr_combi,limit_use,limit_range,curr_arg+1,curr_uses,sum);
  

}
Exemplo n.º 2
0
void combi(char *s, char *s1)
{
	char t[100] = {0};
	if (strlen(s) == 0)
	{
		printf("%s\n", s1);
		return;
	}
	strcpy(t, s1);
	combi(s+1, t);
	int n = strlen(t);
	t[n] = s[0]; t[n+1] = '\0';
	combi(s+1, t);
}
Exemplo n.º 3
0
//--------------------------------------------------------------
void ofApp::draw(){
    
    
    ofDrawBitmapString("nCm % x == 0:light",10,50);
    ofDrawBitmapString("nCm % x != 0:dark",10,40);
    ofDrawBitmapString("push  1  key:x=1",10,30);
    ofDrawBitmapString("push any key:x++",10,20);
    ofDrawBitmapString("x:"+ofToString(x),10,10);
    
    double center = STEP * SIZE / 2;
    for(int i = 0 ;i <= STEP; i++){
        for (int j = 0; j <= i; j++) {
            int c = combi(i, j);
            
            //枠
            ofSetColor(0,0,0);
            ofRect((i/2.0-j)*SIZE + center, i*SIZE, SIZE, SIZE);
            
            //中身
            ofSetColor(64+200*(c%x==0),64+200*(c%x==0),64+200*(c%x==0));
            ofRect((i/2.0-j)*SIZE + center+1.5, i*SIZE+1.5, SIZE-3, SIZE-3);
            
            //数字
            ofSetColor(0, 0, 0);
            string text = ofToString(c);
            //string text = string((4-(int)log10(c))/2,' ') + ofToString(c);
            //std::cout<<(4-(int)log10(c))<<":"<<text<<std::endl;
            ofDrawBitmapString(text,(i/2.0-j)*SIZE+center+SIZE/9, i*SIZE+SIZE*3/5);
            
        }
    }
}
Exemplo n.º 4
0
// s 表示要排列的資料
// n 表示此陣列的大小
// m 表示要選出的數量
// pos 表示要排列pos ~ n-1之間選出m-got個資料
// got 表示已經選好的個數
void combi(char *s, int n, int m, int pos, int got) {
    int i;
    // 請問終止條件
    if (m == got) {
        // 印出來看對不對
        for (i = 0; i < m; i++) 
            printf("%c", s[i]);
        printf("\n");
        return;
    }
    //如何化簡?
    //由pos道n-1間可以任選出i位置的元素
    for (i = i; i <= n-1; i++) {
        //如何選定?選定到哪個位置?
        //應該選到 got 這個位置上!
        //若採用 swap(got,i) 的方式選擇, 那程式應該這樣寫
        tmp = s[i];
        s[i] = s[got];
        s[got] = tmp;
        //接下來如何recursion?
        //由 i+1 開始選, 因為組合和位置無關, 前面選過的組合不能再選
        /* Example
           A B C D E  c(5, 2)
           A -> AB, AC, AD, AE
           B -> BC ,BD, BE
           C -> CD, CE
           E -> DE
        */
        combi(s, n, m, i+1 , got+1);
        //recursion 完要記得還原陣列
        tmp = s[i];
        s[i] = s[got];
        s[got] = tmp;
    }
}
Exemplo n.º 5
0
int paint()
{
    int i, n, r;

    for(n = 0; n <= N; n++)
    {
        for(r = 0; r <= n; r++)
        {
            if(0 == r)   //打印空格
            {
                for(i = 0; i <= (N-n); i++)
                {
                    printf("   ");
                }
            }
            else
            {
                printf("   ");
            }  //打印空格结束
            printf("%3d", combi(n,r));
        }
        printf("\n");
    }

    return 0;
}
Exemplo n.º 6
0
int main() {
    array();
    tuple();
    unordered_map();
    unordered_set();
    forward_list();
    combi();
}
Exemplo n.º 7
0
main()
{
	char s[100], s1[100];
	printf("Enter the string : ");
	scanf("%s", s);
	strcpy(s1, s);
	permut(s, 0);
	combi(s1, "");
}
Exemplo n.º 8
0
void combinator_main(){
	int n, r;
	for(n = 0; n <= 5; n++){
		for(r = 0; r <= n; r++){
			printf("%d C %d=%ld  ", n, r, combi(n, r));
		}
		printf("\n");
	}
}
Exemplo n.º 9
0
int main(void)
{
    int n,r;

    for (n = 0; n <= 5; n++) {
        for (r = 0; r <= n; r++)
            printf("%dC%d=%ld " ,n,r,combi(n,r));
        printf("\n");
    }
}
Exemplo n.º 10
0
 int main()
 {
 int t, n, r;
 scanf("%d", &t);
 while(t--)
 {
 scanf("%d %d", &n, &r);
 long long int ans = combi(n, r);
 printf("%lld\n", ans);
 }
 return 0;
 }
Exemplo n.º 11
0
int make_limit(int curr_combi[9], int curr_pos){
  
  bool val[MAX];
  for(int i=0;i<MAX;i++) val[i]=false;
  for(int i=0;i<=curr_combi[curr_pos];i++) val[i]=true;
			   
  for(int i=1;i<=num_stamp;i++)
    combi(val,curr_combi,i,curr_pos,0,0,0);
    
  for(int i=1;i<MAX;i++) if(val[i]==false) return i;

}
Exemplo n.º 12
0
void main(void)
{
  int n, r, t;
  for (n = 0; n <= N; n++){
    for (t = 0; t < (N - n) * 3; t++){
      printf(" ");
    }
    for (r = 0; r <= n; r++){
      printf("%3ld   ", combi(n, r));
    }
    printf("\n");
  }
}
lld combi(lld n, lld k,lld m)
{
	if(n<k)
		return 0;
	if(n-k<k)
		return combi(n,n-k,m);
	lld i,p=1,t=1;
	for(i=n-k+1;i<=n;i++)
		p=(p*i)%m;
	for(i=1;i<=k;i++)
		t=(t*i)%m;
	return (p*inverse_modulo(t,m))%m;
}
Exemplo n.º 14
0
int main(void)
{
	int n,r,t;
	for (n=0;n<=N;n++)
	{
		for (r=0;r<=n;r++)
		{
			int i;		//排版设定开始
			if (r==0)
			{
				for (i=0;i<=(N-n);i++)
					printf("  ");
			}
			else
				printf("  ");	//排版设定结束
			printf("%3d",combi(n,r));
		}
		printf("\n");
	}
	return 0;
}
Exemplo n.º 15
0
void paint()
{
	int n, r, t;
	for(n = 0; n <= N; n++) 
	{
		for(r = 0; r <= n; r++) 
		{
			int i;/* 排版设定开始*/
			if(r == 0) 
			{
				for(i = 0; i <= (N-n); i++)
					printf(" ");
			}
			else 
			{
				printf(" ");
			} /* 排版设定结束*/
			printf("%3d", combi(n, r));
		}
		printf("\n");
	}
}
Exemplo n.º 16
0
long combi(int n, int r) {
	if(r == 0 || r == n)
		return 1L;
	else
		return combi(n - 1, r) + combi(n - 1, r - 1);
}
Exemplo n.º 17
0
int combi(int a,int b){//aCb
    if(a == b || b == 0) return 1;
    return combi(a-1,b) + combi(a-1,b-1);
}
Exemplo n.º 18
0
bool	btSubsimplexConvexCast::calcTimeOfImpact(
		const btTransform& fromA,
		const btTransform& toA,
		const btTransform& fromB,
		const btTransform& toB,
		CastResult& result)
{

	btMinkowskiSumShape combi(m_convexA,m_convexB);
	btMinkowskiSumShape* convex = &combi;

	btTransform	rayFromLocalA;
	btTransform	rayToLocalA;

	rayFromLocalA = fromA.inverse()* fromB;
	rayToLocalA = toA.inverse()* toB;


	m_simplexSolver->reset();

	convex->setTransformB(btTransform(rayFromLocalA.getBasis()));

	//btScalar radius = btScalar(0.01);

	btScalar lambda = btScalar(0.);
	//todo: need to verify this:
	//because of minkowski difference, we need the inverse direction
	
	btVector3 s = -rayFromLocalA.getOrigin();
	btVector3 r = -(rayToLocalA.getOrigin()-rayFromLocalA.getOrigin());
	btVector3 x = s;
	btVector3 v;
	btVector3 arbitraryPoint = convex->localGetSupportingVertex(r);
	
	v = x - arbitraryPoint;

	int maxIter = MAX_ITERATIONS;

	btVector3 n;
	n.setValue(btScalar(0.),btScalar(0.),btScalar(0.));
	bool hasResult = false;
	btVector3 c;

	btScalar lastLambda = lambda;


	btScalar dist2 = v.length2();
#ifdef BT_USE_DOUBLE_PRECISION
	btScalar epsilon = btScalar(0.0001);
#else
	btScalar epsilon = btScalar(0.0001);
#endif //BT_USE_DOUBLE_PRECISION
	btVector3	w,p;
	btScalar VdotR;
	
	while ( (dist2 > epsilon) && maxIter--)
	{
		p = convex->localGetSupportingVertex( v);
		 w = x - p;

		btScalar VdotW = v.dot(w);

		if ( VdotW > btScalar(0.))
		{
			VdotR = v.dot(r);

			if (VdotR >= -(SIMD_EPSILON*SIMD_EPSILON))
				return false;
			else
			{
				lambda = lambda - VdotW / VdotR;
				x = s + lambda * r;
				m_simplexSolver->reset();
				//check next line
				w = x-p;
				lastLambda = lambda;
				n = v;
				hasResult = true;
			}
		} 
		m_simplexSolver->addVertex( w, x , p);
		if (m_simplexSolver->closest(v))
		{
			dist2 = v.length2();
			hasResult = true;
			//printf("V=%f , %f, %f\n",v[0],v[1],v[2]);
			//printf("DIST2=%f\n",dist2);
			//printf("numverts = %i\n",m_simplexSolver->numVertices());
		} else
		{
			dist2 = btScalar(0.);
		} 
	}

	//int numiter = MAX_ITERATIONS - maxIter;
//	printf("number of iterations: %d", numiter);
	result.m_fraction = lambda;
	result.m_normal = n;

	return true;
}