c++--noip2016 Improve group Day1 t3--Change Classroom __c++

Source: Internet
Author: User
Topic Description

The first question he faces about college cows is how to apply for the right course based on the actual situation.

In the course of choice, there are 2n classes scheduled for n time periods. During the first (1≤i≤n) time period, two courses of the same course are conducted at different locations, in which cattle are arranged in the class CI in advance and another in the classroom di.

Without submitting any applications, students need to complete all the N-section scheduled courses in chronological order. If students want to change classrooms in section I, they will need to apply. If the application is approved, students can go to Class di in the first time period, otherwise they will still be in the classroom CI class.

As there is too much demand for changing classrooms, the application may not be approved. by calculating, the probability that an application is passed is a known real ki, and the probability that the application for different courses is passed is independent of the number of cows found applying for the replacement of Class I classes.

The school stipulates that all applications can be submitted only once before the start of the semester, and that each person can only select up to M courses to apply. This means that cattle and cows must decide at once whether to apply for replacement of each class of classrooms, it is not possible to decide whether or not to apply for other courses based on the results of certain courses; cattle and cows can apply for their most hope to change the classroom of the M course, you can not finish this m application opportunities, or even a course does not apply.

Because different courses may be arranged in different classrooms, cattle and cows need to use recess time to get from one classroom to another.

Niuniu's University has a V-classroom, with an e-road. Each road is connected to two classrooms and can be used in two-way traffic. Depending on the length of the road and the degree of congestion, the energy expended on different roads may vary. After the end of Class I (1≤i≤n-1), Niu Niu will start from the classroom of this class, choose a path that takes the least effort to go to the classroom of the next class.

Now cows want to know which courses you can apply to minimize the amount of physical energy you spend moving between classrooms, and ask you to help him find the minimum. Input Format

The first line is a four integer n,m,v,e. n indicates the number of time periods in the semester; M indicates the maximum number of classes the cow can apply for changing classrooms; v indicates the amount of classrooms in the cattle and cattle schools; e indicates the number of roads in the school of cattle and cows.

The second row n positive integers, the first I (1≤i≤n) A positive integer represents CI, that is, the first time period cattle cattle are arranged class classroom; Guarantee 1≤ci≤v.

The third row n positive integers, the first I (1≤i≤n) A positive integer represents Di, that is, the first time period, another classroom of the same course; Guarantee 1≤di≤v.

The third line n a real number, the first (1≤i≤n) real number represents Ki, that is, bovine cattle to apply for the first time to replace the classroom to obtain the probability of passing. Guarantee 0≤ki≤1.

Next line E, three positive integers for each line. AJ, BJ, WJ, said there is a two-way road connecting the classroom AJ, BJ, the physical value needed to pass this road is WJ; guarantee 1≤aj,bj≤v,1≤wj≤100

Guarantee 1≤n≤2000,0≤m≤2000,1≤v≤300,0≤e≤90000.

Make sure that you can get to all the other classrooms from any classroom through the roads in the school.

guarantees that the input real number contains a maximum of 3 decimal digits. output Format

The output line, containing a real number, is rounded to exactly 2 digits after the decimal point, indicating the answer. Your output must be exactly the same as the standard output.

The test data guarantees that the absolute value of the difference between the rounded answer and the exact answer is less than 4x10-3. (If you don't know what a floating-point error is, this passage can be understood as: For most algorithms, you can normally use a floating-point type without special processing of it) sample Data 1


3 2 3 3
2 1 2
1 2 1
0.8 0.2 0.5
1 2 5
1 3 3
2 3 1

Output 2.80 notes

"Sample 1 description"
All feasible application options and expected benefits are as follows:


1. There may be multiple two-way roads connecting the same two classrooms in the road. It is also possible that the two ends of the road are connected in the same room.

2. Please note that the significance of distinguishing n,m,v,e, n is not the number of classrooms, M is not the number of roads.

"Data size and Convention"

Special Property 1: The Ai,bi,ai≠bi of any two points in the picture, the existence of a path that takes the least amount of energy, contains only one way.

Special Property 2: For all 1≤i≤n,ki=1.

#include <cstdio> #include <cstring> #include <algorithm> using namespace std;
int a[2001],b[2001],f[301][301];
Double ans,p[2001],dp[2001][2001][2];  
    inline int readint () {int i=0;  
    Char ch; For (Ch=getchar ();ch< ' 0 ' | |  
    Ch> ' 9 '; Ch=getchar ());  
    for (; ch>= ' 0 ' && ch<= ' 9 '; Ch=getchar ()) i= (i<<3) + (i<<1) +ch-' 0 ';  
return i;
	int main () {int n,m,e,v,s,t,k;
	N=readint ();
	M=readint ();
	V=readint ();
	E=readint ();
	for (int i=1;i<=n;++i) a[i]=readint ();
	for (int i=1;i<=n;++i) b[i]=readint ();
	for (int i=1;i<=n;++i) scanf ("%lf", &p[i));
	for (int i=1;i<=v;++i) for (int j=1;j<=v;++j) if (i!=j) f[i][j]=1000000000;
		for (int i=1;i<=e;++i) {s=readint ();
		T=readint ();
		K=readint ();
		F[s][t]=min (F[S][T],K);
	F[t][s]=min (F[T][S],K); for (int k=1;k<=v;++k) for (int i=1;i<=v;++i) for (int j=1;j<=v;++j) f[i][j]=min (F[I][J],F[I][K]+F[K][J)
	); for (int i=1;i<=n;++i) for (iNT J=0;j<=m;++j) dp[i][j][1]=dp[i][j][0]=1000000000;
	dp[1][1][1]=dp[1][0][0]=0; for (int i=1;i<n;++i) for (int j=0;j<=m;++j) {dp[i+1][j][0]=min (dp[i][j][1]+p[i]*f[b[i]][a[i+1]]+ (1.0-p[i)) *f[
			A[I]][A[I+1]],DP[I][J][0]+F[A[I]][A[I+1]]); Dp[i+1][j+1][1]=min (dp[i][j][1]+p[i]*p[i+1]*f[b[i]][b[i+1]]+ (1.0-p[i)) *p[i+1]*f[a[i]][b[i+1]]+p[i]* (1.0-p[i+1) ) *f[b[i]][a[i+1]]+ (1.0-p[i]) * (1.0-p[i+1]) *f[a[i]][a[i+1]],dp[i][j][0]+p[i+1]*f[a[i]][b[i+1]]+ (1.0-p[i+1)) *f[a[
	Double ans=1000000000;
	for (int i=0;i<=m;++i) ans=min (Ans,min (dp[n][i][0],dp[n][i][1));
	printf ("%0.2f\n", ans);
return 0; }

Related Article

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.