Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:为什么不是0MS?

Posted by CSU_ACM1174 at 2011-08-04 14:50:32 on Problem 1695
In Reply To:Re:为什么不是0MS? Posted by:CSU_ACM1174 at 2011-08-04 14:49:58
#include<stdio.h>
#include<string.h>
#define MAX 31

int min(int a,int b,int c)
{
  int t;
  t=a<b?a:b;
  return t<c?t:c;
}
  
  
int dp[MAX][MAX][MAX];
int T[MAX][MAX];

int main()
{
  int n,m,i,j,k;
  scanf("%d",&n);
  while(n--)
  {
    scanf("%d",&m);
    memset(dp,0,sizeof(dp));
    for(i=1;i<m;i++)
      for(j=i+1;j<=m;j++)
        scanf("%d",&T[i][j]);
    for(k=m-1;k>=1;k--)
      for(i=1;i<=k;i++)
        for(j=1;j<=k;j++)
         dp[i][j][k]=min(dp[i][j][k+1]+T[k][k+1],dp[i][k][k+1]+T[j][k+1],
                         dp[j][k][k+1]+T[i][k+1]);
    printf("%d\n",dp[1][1][1]);
  }
  return 0;
}
这个是0MS!!

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator