Zoj3411 special judge

Source: Internet
Author: User

Problem description:

The norm of a vectorV= (V1, V2,..., vn)Is defineNorm (V)= |V1| + |V2| +... + |Vn|. And in problem 0000, there areNCases, the standard output is recorded as a vectorX= (X1, x2,..., xn). The output of a submitted solution is also records as a vectorY= (Y1, Y2,..., yn). The submitted solution will be accepted if and only ifNorm (x-y)M(A given tolerance ).

Knowing that all the outputXIAre in range [A,B], An incorrent solution that outputs integerYiIn range [A,B] With equal probability may also get accepted. Given the standard outputXI, You are supposed to calculate the possibility of getting accepted using such solution.

N,M,A,B(1 ≤N,M≤ 50,-50 ≤A<B≤ 50)

Accepted 3411 Java 380 Ms 9938 K
  Import  Java. util.  * ;
Import Java. Math. * ;

Public Class Main {
Public Static Void Main (string [] ARGs ){
Int N, m, a, B, X [] = New Int [ 51 ];
Biginteger d [] [] = New Biginteger [ 51 ] [ 51 ], F1, F2, F3;
Scanner CIN = New Using (system. In );
While (CIN. hasnext ()){
N = Cin. nextint ();
M = Cin. nextint ();
A = Cin. nextint ();
B = Cin. nextint ();
// System. Out. println (n + "" + M + "" + A + "" + B );
Int I, J, K, T;
For (I = 1 ; I <= N; I ++ )
X [I] = Cin. nextint ();
For (I = 0 ; I <= N; I ++ )
For (J = 0 ; J <= M; j ++ )
D [I] [J] = Biginteger. zero;
For (I = A; I <= B; I ++ ){
T = Math. Abs (I - X [ 1 ]);
// System. Out. println (t );
If (T <= M ){
D [ 1 ] [T] = D [ 1 ] [T]. Add (biginteger. One );
// System. Out. println ("d [1] [" + T + "] =" + d [1] [T]);
}
}

For (I = 2 ; I <= N; I ++ ){
For (J = A; j <= B; j ++ ){
T = Math. Abs (J - X [I]);
If (T <= M ){
For (K = T; k <= M; k ++ ){
D [I] [k] = D [I] [K]. Add (d [I - 1 ] [K - T]);
// System. Out. println ("d [" + I + "] [" + K + "] =" + d [I] [k]);
}
}
}
}
F1 = Biginteger. zero;
For (I = 0 ; I <= M; I ++ )
F1 = F1.add (d [N] [I]);
F2 = Biginteger. One;
For (I = 1 ; I <= N; I ++ )
F2 = F2.multiply (biginteger. valueof (B - A + 1 ));
// System. Out. println (F1 + "" + F2 );
F3 = F1.gcd (F2 );
F1 = F1.divide (F3 );
F2 = F2.divide (F3 );
System. Out. println (F1 + " / " + F2 );
}
}
}
/*
1 1 0 2
1
4 2 2 5
2 3 2 4
4 3 2 5
2 3 2 4

1/1
3/32
7/32
*/

CodeThe core part is lines 30-40. That's simple...

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.