Ejemplo n.º 1
0
int main()
{
	int caseNum;
	int ii, jj, kk, tt;
	int temp;
	int n;
	int maxInside, pre_s, cur_prob;
	int tempprob;
	int flag;
	int glbMax;
	int count;
	state_t *state_pre;
	state_t *state_cur;
	state_t *state_tmp;

	scanf("%d", &caseNum);

	while(caseNum --)
	{
		scanf("%d", &n);
		for(ii = 0; ii < n; ii ++)
		{
			timeUseMin[ii] = 512;
		}

		for(ii = 0; ii < 3; ii ++)
		{
			for(jj = 0; jj < n; jj ++)
			{
				scanf("%d", &timeUse[ii][jj]);
				timeUseMin[jj] = timeUseMin[jj] < timeUse[ii][jj] ? 
						 timeUseMin[jj] : timeUse[ii][jj];
			}
		}

		qsort(0, n-1);
		state_pre = &state_pool1;
		state_cur = &state_pool2;

		memset(f, 0, sizeof(f));
		memset(state_pre, 0, sizeof(state_t));
		memset(state_cur, 0, sizeof(state_t));

		state_cur -> num = 0;
		glbMax = 0;
		count = -1;
		memset(state_map, 0, sizeof(state_map));

		while(state_cur -> num >= 0)
		{
			count ++;
			if(count == n)break;
			state_tmp = state_pre;
			state_pre = state_cur;
			state_cur = state_tmp;
			state_cur -> num = -1;
			for(jj = 0; jj <= (state_pre -> num); jj ++)
			{
				for(tt = 280; tt >= 0; tt --)
					for(kk = 1; kk <= 3; kk ++)
					{
						flag = 0;
						maxInside = count;
						for(cur_prob = 0; cur_prob < n; cur_prob ++)
						{
							if(tt < timeUseMin[cur_prob]) break;
							if(timeUse[kk-1][cur_prob] > tt) continue;
							if(_testbit((state_pre -> state[jj]), cur_prob) == 1)
								continue;
							for(ii = 1; ii <= 3; ii ++)
							{
								if(((state_pre -> state[jj]) != 0) &&
								   (ii == kk)) 
								   continue;
								temp = f[ii][state_pre -> state[jj]]
								        [tt - timeUse[kk-1][cur_prob]] + 1;
								if(temp > maxInside)
								{
									maxInside = temp;
									pre_s     = state_pre ->
									            state[jj];
									tempprob  = cur_prob;
									flag = 1;
								}
							}
						}
						if(flag == 1)
						{
							_setbit(pre_s, tempprob, 1);
							f[kk][pre_s][tt] = maxInside;
							if( maxInside > glbMax) glbMax = maxInside;

							if( !state_map[pre_s])
							{
								state_cur -> num ++;
								state_cur -> state[state_cur -> num] = pre_s;
								state_map[pre_s] = 1;
							}
						}
					}
			}
		}

		printf("%d\n", glbMax);
	}
	return 0;
}
Ejemplo n.º 2
0
//---------------------------------------------------------------------------------------
static void __inline__ __pindir(int portpin, int direction)
// Sets the port direction 
{
  if(direction == 0x02) // OUT out
  {
      if (portpin < 0x20)
      {
          _setbit(P1DIR,portpin);
          _resetbit(P1SEL,portpin);
          _resetbit(P1REN,portpin);
      } else {
          _setbit(P2DIR,portpin);
          _resetbit(P2SEL,portpin);
          _resetbit(P2REN,portpin);
      }
  }
  else if (direction == 0x00)    // IN input
  {
      if (portpin < 0x20)
      {
          _resetbit(P1DIR,portpin);
          _resetbit(P1SEL,portpin);
          _resetbit(P1REN,portpin);
      } else {
          _resetbit(P2DIR,portpin);
          _resetbit(P2SEL,portpin);
          _resetbit(P2REN,portpin);
      }
  }
  else if (direction == 0x05)    // INPU input pullup
  {
      if (portpin < 0x20)
      {
          _resetbit(P1DIR,portpin);
          _resetbit(P1SEL,portpin);
          _setbit(P1REN,portpin);
          _setbit(P1OUT,portpin);
      } else {
          _resetbit(P2DIR,portpin);
          _resetbit(P2SEL,portpin);
          _setbit(P2REN,portpin);
          _setbit(P2OUT,portpin);
      }
  }
  else if (direction == 0x04)    // INPD input pulldown
  {
      if (portpin < 0x20)
      {
          _resetbit(P1DIR,portpin);
          _resetbit(P1SEL,portpin);
          _setbit(P1REN,portpin);
          _resetbit(P1OUT,portpin);
      } else {
          _resetbit(P2DIR,portpin);
          _resetbit(P2SEL,portpin);
          _setbit(P2REN,portpin);
          _resetbit(P2OUT,portpin);
      }
  }
  else if (direction == 0x0a)    // PULSEOUT pulse circuit output
  {
      if (portpin < 0x20)
      {
          _setbit(P1DIR,portpin);
          _setbit(P1SEL,portpin);
          _resetbit(P1REN,portpin);
      } else {
          _setbit(P2DIR,portpin);
          _setbit(P2SEL,portpin);
          _resetbit(P2REN,portpin);
      }
  }


}