UOJ262 "NOIP2016" Change classroom

Source: Internet
Author: User

This article is copyright ljh2000 and Blog Park is shared, welcome reprint, but must retain this statement, and give the original link, thank you for your cooperation.

  this article ljh2000
Author Blog: http://www.cnblogs.com/ljh2000-jump/
Reprint please specify the source, infringement must investigate, retain the final interpretation right!
 DescriptionThe first question he faces when it comes to college cows is how to apply for the right course based on the actual situation. In the courses you can choose, there are 2n sectionsThe course is arranged in n time periods. At the time of paragraph I (1≤i≤n), two courses with the same contents are carried out at different locations, in which cattle and cattle are pre -is arranged in the classroom CI class, while another class is in the Classroom di. Without submitting any application, students are required to complete the sequence in chronological orderinto all the courses arranged in the N-section. If the student wants to change the classroom for the section I course, an application will be required. If the application is approved, the student maytime period to the Classroom Di class, or Still in class CI class. As there is too much need to change classrooms, the application may not be approved. By calculation, cattle and cattleThe probability that the application is passed is a known real ki, and the probability that the application for different courses is passed, when a classroom is found to have applied for the replacement of section I coursesare independent of each other. The school stipulates that all applications can only be submitted at one time before the beginning of the semester, and each person can only select up to M courses to apply. This means that cows and cows must decide whether or not to apply for replacement of each class in the classroom, and not to decide whether or not other courses are eligible forplease, OX and OX can apply for the M-gate course which they most want to change the classroom, also can not complete the opportunity of M application, even can not apply for a course. Becausefor different courses may be arranged in different classrooms, so cattle and cows need to use recess time from one classroom to another classroom. where NiuniuThe university has a V classroom, there is a road of E. Each road connects two classrooms and is accessible in both directions. Because the length of the road and the degree of congestion are different,the physical strength that is spent on different roads may vary. At the end of Class I (1≤i≤n-1), cattle and cows will depart from the classroom in this class and choose aThe least laborious path to the next class classroom. Now cattle and cows want to know which courses to apply for him to move through the classroom between the cost of the bodyThe value of the sum of the force values is the smallest, please help him to find this minimum value. InputThe first row of four integers n,m,v,e. n indicates the number of time periods within this semester, and M indicates the maximum amount of cattle and cows that can be applied for replacement classes;v indicates the number of classrooms in cattle and cattle schools, and E indicates the number of roads in cattle and cattle schools. The second row n positive integers, and the first I (1≤i≤n) positive integers denote C, that is, the class I time period the cattle are arranged to class classroom; Guarantee 1≤ci≤v. The third row n positive integers, the first I (1≤i≤n) positive integers denote di, that is, the second time period of the same course in the classroom; Guarantee 1≤di≤v. The fourth row n real numbers, the first I (1≤i≤n) of the real number represents Ki, that is, the probability of the cow ox applying to change classrooms in the first time period. Guaranteed 0≤ki≤1. The next e-line, three positive integers per line AJ,BJ,WJ, indicates that there is a two-way road connecting to the classroom AJ,BJ, through which the physical value of the road is WJ;guaranteed 1≤aj,bj≤v,1≤wj≤100. guaranteed 1≤n≤2000,0≤m≤2000,1≤v≤300,0≤e≤90000. guaranteed access to all other classrooms through the school's roads, from any classroom. ensure that the real number entered is a maximum of 3 decimal places.  OutputThe output line contains a real number, four 淫悦の学舎 five into exactly 2 digits after the decimal point, indicating the answer. of yourthe output must be exactly the same as the standard output to be correct. The test data guarantees that the absolute value of the difference between the answer and the exact answer of the four 淫悦の学舎 five is not less than 4*10^-3. (If you don't know what a floating-point error is, this passagecan be understood as: For most algorithms, you can use the floating-point type normally without special handling of it . Sample Input3 2 3 3
2 1 2
1 2 1
0.8 0.2 0.5
1 2 5
1 3 3
2 3 1Sample Output2.80   Positive Solution: Probability Dp+floydProblem Solving Report:

24 min

Note that there are 6 test points m=0, it is not possible to apply, then only need to ask for the full figure of the shortest between 22, the path is only determined.

52 min

Note that there are 7 additional test points m=1, only one application can be submitted. We can directly enumerate where to put the application, and then do not apply for the time to take a min on it.

76 min

Note that there are also 6 test points m=2, can only make two applications, violent enumeration which two points to apply.

80 min

In fact, we do not need to divide so many kinds of discussion, consider the direct search, whether the application at each point, the final violent calculation contribution. Because this complexity is C (n,m), so m<=2 and n<=10 is completely no problem, directly can be used to search to get 80 points.

100 min

This is obviously a probability dp naked problem. Consider F[i][j][0, 1] represents the first I class, has applied for J times, this application does not apply the minimum expectations, then:

$${f[i][j][0]=min (F[i-1][j][0]+dis (C[i-1],c[i]), F[i-1][j][1]+dis (C[i-1],c[i]) * (1-p[i-1]) +dis (D[i-1],c[i]) *p[i] )}$$

$${f[i][j][1]=min (F[i-1][j-1][0]+dis (C[i-1],d[i]) *p[i]+dis (C[i-1],c[i]) * (1-p[i]), F[i-1][j-1][1]+dis (c[i-1],c[i ]) * (1-p[i-1]) * (1-p[i]) +dis (C[i-1],d[i]) * (1-p[i-1]) *p[i]+dis (D[i-1],c[i]) *p[i-1]* (1-p[i)) +dis (D[i-1],d[i]) *p[ I-1]*p[i])}$$

(Dis (i,j) indicates the shortest distance from I to j)

It should be stated that the expectation is added linearly, that is, the total expected value of the distance on a path is actually equal to the sum of the expected value of the distance between each of the two adjacent points. In addition, the above-mentioned transfer can be understood as follows: In the case where we have already filed an application, the discussion of all cases is the desired distance expected in the case of an existing application, in fact based on the calculation of the contribution of each side.

This gives you a perfect score. Complexity of Time: O (V3+NM)

Precautions

If the status of 0, 1 indicates that the location in C or D will be a lot of problems, because it can not reflect the time of the application of the success and failure results, but for the m<=2 point of the basic will not be wrong, big point of error probability is not particularly large, The state design that led to such a complete error was 88 points under the league data ...

 
1 //It's made by ljh20002#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <algorithm>8#include <ctime>9#include <vector>Ten#include <queue> One#include <map> A#include <Set> -#include <string> - using namespacestd; thetypedefLong LongLL; - Const intMAXN = .; - Const intMaxd =311; - Const intINF = (1<< in);  + intN,m,d,bian,c[maxn],d[maxn],dis[maxd][maxd]; - Doublef[maxn][maxn][2],k[maxn],ans; +  AInlineintGetint () { at     intw=0, q=0;CharC=getchar (); while((c<'0'|| C>'9') && c!='-') c=GetChar (); -     if(c=='-') q=1, C=getchar (); while(c>='0'&&c<='9') w=w*Ten+c-'0', C=getchar ();returnq?-w:w; - } -  -InlinevoidWork () { -N=getint (); M=getint (); D=getint (); Bian=getint ();intX,y,z,lim;DoubleMinl; in      for(intI=1; i<=n;i++) C[i]=getint (); for(intI=1; i<=n;i++) D[i]=getint (); for(intI=1; i<=n;i++) scanf ("%LF",&k[i]); -      for(intI=1; i<=d;i++) for(intj=1; j<=d;j++) dis[i][j]=inf; to      for(intI=1; i<=bian;i++) { +X=getint (); Y=getint (); Z=getint ();if(Dis[x][y]==inf) dis[x][y]=dis[y][x]=Z; -         ElseDis[x][y]=min (dis[x][y],z), dis[y][x]=Dis[x][y]; the     } *      for(intL=1; l<=d;l++) for(intI=1; i<=d;i++)if(i!=l) for(intj=1; j<=d;j++)if(j!=l&&i!=j) Dis[i][j]=min (dis[i][l]+Dis[l][j],dis[i][j]);  $      for(intI=1; i<=n;i++) for(intj=0; j<=m;j++) f[i][j][0]=f[i][j][1]=1e30; f[1][0][0]=f[1][1][1]=0; Panax Notoginseng      for(intI=1; i<=d;i++) dis[i][i]=0; -      for(intI=2; i<=n;i++) { thelim=min (i,m); +          for(intj=0; j<=lim;j++) { Aminl=f[i-1][j][1]+dis[c[i-1]][c[i]]* (1.0-k[i-1]) +dis[d[i-1]][c[i]]*k[i-1]; theMinl=min (minl,f[i-1][j][0]+dis[c[i-1]][c[i]]); +f[i][j][0]=min (f[i][j][0],minl); -             if(j>=1) { $minl=f[i-1][j-1][1]+dis[c[i-1]][c[i]]* (1.0-k[i]) * (1.0-k[i-1]) +dis[c[i-1]][d[i]]* (1.0-k[i-1])*K[i]; $minl+=dis[d[i-1]][c[i]]*k[i-1]*(1-k[i]) +dis[d[i-1]][d[i]]*k[i-1]*K[i]; -Minl=min (minl,f[i-1][j-1][0]+dis[c[i-1]][d[i]]*k[i]+dis[c[i-1]][c[i]]* (1.0-k[i])); -f[i][j][1]=min (f[i][j][1],minl); the             } -         }Wuyi     } theAns=1e30; for(intI=0; i<=m;i++) Ans=min (Ans,min (f[n][i][0],f[n][i][1])); -printf"%.2LF", ans); Wu } -  About intMain () $ { - Work (); -     return 0; -}

UOJ262 "NOIP2016" Change classroom

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.