int main(int argc, char* argv[])
{
#ifndef ONLINE_JUDGE
 
freopen("test.in", "r", stdin);
#endif
 
Scanner sc;
int t = sc.nextInt();int n,i,j;
while(t--)
{
	//scanf("%d",&n);
	n=sc.nextInt();
	int ar[n][n]
	;
	for(i=0;i<n;i++)
	for(j=0;j<=i;j++)
	//scanf("%d",&ar[i][j]);
	ar[i][j]=sc.nextInt();
	
	for(i=n-1;i>0;i--)
	for(j=0;j<i;j++)
	ar[i-1][j]+=ar[i][j]>ar[i][j+1]?ar[i][j]:ar[i][j+1];
	
	printf("%d",ar[0][0]);
	printf("\n");
	}
	return 0;
}
Exemple #2
0
int main( int argc, char* argv[] ) {
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	#endif

	Scanner sc;

	//int tc = sc.nextInt();
	int tc=1;
	while(tc--){
		//int m = sc.nextInt();
		//int n = sc.nextInt();
		int n,m;
		scanf("%d%d",&n,&e);
		m=n;
		int s=n+m; //source node
		int t=n+m+1;//sink node
		graphClear(n+m+2);//total nodes are n+m+2
		rep(i,m) {
			int a=sc.nextInt();
			addEdge(s, i, a, 0);//addEdge(source,destination,capacity,cost)
		}
		rep(j,n) {
			int b=sc.nextInt();
			addEdge(m+j, t, b, 0);//addEdge(source,destination,capacity,cost)
		}
 public static void main(String args[])
 {
     Scanner in = new Scanner(System.in);
     int t,i,j,k;
     t = in.nextInt();
     for(i=0;i<t;i++)
     {
         int n;
         n = in.nextInt();
         int[] a = new int[5];
         for(j=0;j<n;j++)
         {
             a[j]=in.nextInt();
         }
         for(j=0;j<n;j++)
         {
             for(k=j;k<n;k++)
             {
                 if(a[j]<a[k])
                 {
                     int s=a[j];
                     a[j]=a[k];
                     a[k]=s;
                 }
             }
         }
         for(j=0;j<n;j++)
         System.out.print(a[j] + " ");
         System.outprintln();
     }
 }
Exemple #4
0
int main()
{
	scanf("%d %d",&V,&E);

	ne = 0;
	memset(last, -1, sizeof last);
	memset(next, -1, sizeof next);
	memset(parent, -1, sizeof parent);
	memset(rank, 0, sizeof rank);

	Scanner inp;

	for(int i=0 ; i<E ; i++)
	{
		//scanf("%d %d %d", &e[i].s, &e[i].t, &e[i].w);
		e[i].s = inp.nextInt();
		e[i].t = inp.nextInt();
		e[i].w = inp.nextInt();
		e[i].w = - e[i].w;
	}

	//for(int i=0 ; i<V ; i++) parent[i] = i, rank[i] = 0;

	qsort(&e, E, sizeof(edges), cmp);

	int k=0;	
	for(int i=0 ; i<E && k<V-1; i++)
	{
		int u = find(e[i].s);
		int v = find(e[i].t);
		if(u != v)
		{
			addedge(e[i].s, e[i].t, -e[i].w);
			addedge(e[i].t, e[i].s, -e[i].w);
			k++;
			_union(u,v);
		}
	}
	
	for(int i=0 ; i<V ; i++)
	{
		getScore(i);
		for(int j=0 ; j<V ; j++)
			printf("%d ", dist[j]);
		printf("\n");
	}
}
	public static void main(String... args)
	{
		int N,T;
      Scanner s = new Scanner(System.in);
      T = s.nextInt();
      N = s.nextInt();
      if((1<=N  && N>=1000000) && (1<=T && T<=10))
              System.exit(0);
      
      int a[][] = new int[N][3];
      for(int i = 0 ;i<N;i++)
      {
       	for(int j = 0;j<3;j++)
        {
          a[i][j]=s.nextInt();  
      	  
//          if(a[i][j] >=100000)
  //            System.exit(0);
        }
     }     
 for(int i = 0 ;i<N;i++)
      {
        for(int j = 0;j<3;j++)
        {
		System.out.println("\t"+a[i][j]);
        }
     }

      int f=0,sum=0;
	  for(int i = 0 ;i<N;i++)
      {
        int min=a[i][0];
        for(int j = 0;j<3;j++)
        {
      		if(min>a[i][j] && f!=j)
            {
              min = a[i][j];
              f=j;
            }
        }
        sum+=min;
      }
      System.out.println(sum+"");
	}	
Exemple #6
0
int main( int argc, char* argv[] ) {
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);	
	#endif

	/*
	freopen("input-nn.txt","w",stdout);
	cout<<1<<endl;
	int n=100000;
	cout<<n<<endl;
	set<pii> s;
	rep(i,n){
	int x=rand();
	int y=rand();
	pii p=mp(x,y);
	if(s.count(p)){i--; continue;}
	s.insert(p);			
	cout<<x<<" "<<y<<endl;
	}
	exit(0);
	*/

	Scanner sc;
	int testCases = sc.nextInt();
	for(int testCase=1;testCase<=testCases;testCase++){
		int n = sc.nextInt();
		vpii p(n);
		rep(i,n){
			p[i].first = sc.nextInt();
			p[i].second= sc.nextInt();
		}

		buildTree(0, n, &(vpii(p)[0]));

		//fprintf(stderr,"time=%.3lfsec\n",0.001*(clock()-start));

		rep(i,n){
			findNearestNeighbour(n, p[i].first, p[i].second);
			printf("%lld\n", closestDist);			
		}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	#endif

	Scanner sc;

	int V1 = sc.nextInt();
	int V2 = sc.nextInt();
	init(V1, V2);
	int e = sc.nextInt();

	while(e--){
		int u = sc.nextInt() - 1;
		int v = sc.nextInt() - 1;
		addEdge(u, v);
	}

	printf("%d\n", maxMatching());

	return 0;
}
Exemple #8
0
int main( int argc, char* argv[] ) {
	#ifndef ONLINE_JUDGE
	freopen("input-nn.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif	

	Scanner sc;
	int testCases = sc.nextInt();
	for(int testCase=1;testCase<=testCases;testCase++){
		int n = sc.nextInt();
		vpii p(n);
		rep(i,n){
			p[i].first = sc.nextInt();
			p[i].second= sc.nextInt();
		}

		root = buildTree(0, n, &(vpii(p)[0]));

		//fprintf(stderr,"time=%.3lfsec\n",0.001*(clock()-start));

		rep(i,n){
			findNearestNeighbour(p[i].first, p[i].second);
			printf("%lld\n", closestDist);			
		}
/*****************************************************************************
 * Function 'readElement'
 * This function takes in a scanner and reads the next integer value, storing
 * it as the element
 *
 * Parameters
 *    inFile: the scanner to be read from
**/
void OneRecord::readElement(Scanner& inFile)
{
  long long inValue = 0;
  inValue = inFile.nextInt();
  this->setElement(inValue);
}