Example #1
0
int main(){
	int i;
	printf("Please input 10 integers:\n");
	for(i=0;i<10;i++)
		scanf("%d",&a[i]);
	printf("max=%d,min=%d,average=%.2f\n",max_a(a),min_a(a),ave_a(a));
	return 0;
}
Example #2
0
static int SampleStub (RolloverEncoder *this_enc)
{
  int d1, d2, d3;
  int prev_val, nval;

  for (prev_val = this_enc->GetRaw ();;) {
    nval = this_enc->GetRaw ();
    d1 = nval - prev_val;
    d2 = (prev_val - MIN_ENC_VAL) + (MAX_ENC_VAL - nval);
    d3 = (MAX_ENC_VAL - prev_val) + (nval - MIN_ENC_VAL);
    this_enc->SetSum (this_enc->GetSum () + min_a (d1, min_a (d2, d3)));
    this_enc->Set_dt (min_a (d1, min_a (d2, d3)));
    prev_val = nval;
    Wait (0.005);
  }

  return OK;
}
int main(void)
{
#if _DEBUG
	freopen("input.txt", "r", stdin);
#endif
	scanf("%d\n", &N);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) 
			scanf("%d ", &a[i][j]);
		scanf("\n");
	}

	int case_num = (1 << N) - 1;

	for (int i = 0; i <= case_num; i++) 
		for (int j = 0; j < MAX_N; j++)  
			d[i][j] = MAX_INT;

	d[1][0] = 0;

	// starting point is fixed as 0.
	for (int s = 2; s <= case_num; s++) {
		for (int i = 0; i < N; i++) {
			if (s & (1 << i)) { // i belongs to s!
				for (int j = 0; j < N; j++) { // Why does it starts from 0 ?
					if ((s & (1 << j))/*s 에는 포함되어야함*/ && 
						(((s - (1 << i)) & (1 << j))) /* j 는 s2 에 포함되어야 함 */ &&
						(a[j][i]) &&
						(i != j)/* 같은것도 안됨 */ )
						d[s][i] = min_a(d[s][i], d[s - (1 << i)][j] + a[j][i]);
				}
			}
		}
	}
	long long sol = MAX_INT;

	for (int i = 0; i < MAX_N; i++) {
		if (a[i][0])
			sol = min_a(sol, d[case_num][i] + a[i][0]);
	}
	
	printf("%ld\n", sol);
	return 0;
}