zoj3411-Special Special Judge-高精度dp

Special Special Judge

Time Limit: 2 Seconds       Memory Limit: 65536 KB

Because of recent update of ZOJ, some special judges were broken. You're requested to fix the special judge for Problem 0000.

The norm of a vector v = (v1, v2, ... , vn) is define as norm(v) = |v1| + |v2| + ... + |vn|. And in Problem 0000, there are n cases, the standard output is recorded as a vector x = (x1, x2, ... , xn). The output of a submitted solution is also records as a vector y = (y1, y2, ... , yn). The submitted solution will be accepted if and only if norm(x - y) ≤ m (a given tolerance).

Knowing that all the output xi are in range [ab], an incorrent solution that outputs integer yi in range [ab] with equal probability may also get accepted. Given the standard output xi, you are supposed to calculate the possibility of getting accepted using such solution.

Input

The input contains no more than 100 test cases. The first line of each case contains 4 integers nmab (1 ≤ nm ≤ 50, -50 ≤ a < b ≤ 50), as described above. Then follows a line contains n integers, x1, x2, ... , xn (a ≤ xi ≤ b), indicating the standard output of the n cases.

Process to end of input.

Output

For each case, output the possibility as a irreducible fraction of getting accepted using the incorrent solution in a single line.

Sample Input
1 1 0 2
1
Sample Output
1/1
 
终有一天能达到WATASHI大神的高度吧!加油吧少年!
 
解题报告:http://blog.watashi.ws/1515/zojmonthly1010/
 
诶,满满的都是泪啊。。。
 
import java.util.*;
import java.math.*;

public class Main {
	static BigInteger dp[][]=new BigInteger [60][60];//不加static会报错,静态方法不能引用一个非静态的成员变量
	//dp[i][j]代表前面i个数,总的误差为j时accepted的output数
	public static void main(String[] args) {
		int n,m,a,b;
		Scanner scan=new Scanner(System.in);
		while(scan.hasNext())
		{
			n=scan.nextInt();
			m=scan.nextInt();
			a=scan.nextInt();
			b=scan.nextInt();
			dp[0][0]=BigInteger.valueOf(1);
			for(int i=1;i<=m;++i)
				dp[0][i]=BigInteger.valueOf(0);
			for(int i=1;i<=n;++i)
			{
				int temp=scan.nextInt();
				for(int j=0;j<=m;++j)
				{
					BigInteger hehe=BigInteger.ZERO;
					for(int k=a;k<=b;++k)
					{
						if((j-Math.abs(temp-k))>=0)
							hehe=hehe.add(dp[i-1][j-Math.abs(temp-k)]);
					}
					dp[i][j]=hehe;
				}
			}
			BigInteger fenzi=BigInteger.ZERO,fenmu=BigInteger.valueOf(b-a+1);
			for(int i=0;i<=m;++i)
				fenzi=fenzi.add(dp[n][i]);
			fenmu=fenmu.pow(n);
			BigInteger my_gcd=fenzi.gcd(fenmu);
			System.out.println(fenzi.divide(my_gcd)+"/"+fenmu.divide(my_gcd));
		}
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值