Zoj 1428 magazine delivery (DP)

Source: Internet
Author: User
Http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemcode = 1428 I read the exercise question first. I thought it was graph theory and asked xsy to check the question .. In the end, you cannot give up. It was only after the end of the afternoon that it was originally a DP. Take the location of three vehicles as the status, J, K as the location of the car that is not moving, and I as the location of the current mobile car. DP [j, k, I] can be composed of DP [j, k, I + 1], DP [J, I, I + 1], DP [K, I, I + 1] Move once.

In addition, with a long memory, macro definition will never be used again in the future. The method for obtaining the maximum value of macro definition always fails and the cause cannot be found.

Code:

# Include <cstdio>
# Include <cstring>
# Include <algorithm>
Using namespace STD;
Int data [31] [31];
Int DP [31] [31] [31];
Int main (){
Int t, n, I, J, K;
Scanf ("% d", & T );
While (t --){
Memset (DP, 0, sizeof (DP ));
Scanf ("% d", & N );
For (I = 1; I <n; I ++)
For (j = I + 1; j <= N; j ++)
Scanf ("% d", & Data [I] [J]);
For (I = n-1; I> = 1; I --)
For (j = 1; j <= I; j ++)
For (k = 1; k <= I; k ++ ){
DP [J] [k] [I] = min (DP [J] [k] [I + 1] + data [I] [I + 1], DP [k] [I] [I + 1] + data [J] [I + 1]);
DP [J] [k] [I] = min (DP [J] [k] [I], DP [J] [I] [I + 1] + data [k] [I + 1]);
}
Printf ("% d \ n", DP [1] [1] [1]);
}
Return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.