日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ZOJ 3380 Patchouli's Spell Cards——组合数+概率dp

發布時間:2024/3/12 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ZOJ 3380 Patchouli's Spell Cards——组合数+概率dp 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題意:

m個位置,每個位置可以等概率填n種數,規定一個數字出現次數不能超過L次(注意不是連續L次),填完m個位置后滿足約束的概率是多少。

思路:

定義dp[i][j]為前i種數字填充j個位置(j個位置不必連續)的方案數,那么

dp[i][j]=∑(1<=k&&k<L&&k<=j)dp[i-1][j-k]*C[m-(j-k)][k],C為組合數

結果就是(n^m-dp[n][m])/n^m

import java.util.*; import java.io.*; import java.math.*; public class Main {static BigInteger [][] C = new BigInteger [110][110];static BigInteger [][] dp = new BigInteger [110][110];public static void main(String [] args) {Scanner cin = new Scanner(new BufferedInputStream(System.in));C[0][0] = BigInteger.ONE;for (int i = 1; i <= 100; i++) {C[i][0] = C[i][i] = BigInteger.ONE;for (int j = 1; j < i; j++) {C[i][j] = C[i-1][j].add(C[i-1][j-1]);}}int m, n, l;while (cin.hasNext()) {m = cin.nextInt(); n = cin.nextInt(); l = cin.nextInt();if (l > m) {System.out.println("mukyu~");continue;}for (int i = 0; i <= n; i++) {for (int j = 0; j <= m; j++) {dp[i][j] = BigInteger.ZERO;}}dp[0][0] = BigInteger.ONE;for (int i = 1; i <= n; i++) {for (int j = 0; j <= m; j++) {for (int k = 0; k < l && k <= j; k++) {dp[i][j] = dp[i][j].add(dp[i-1][j-k].multiply(C[m-(j-k)][k]));}}}BigInteger y = BigInteger.valueOf(n).pow(m);BigInteger x = y.subtract(dp[n][m]);BigInteger z = x.gcd(y);x = x.divide(z);y = y.divide(z);System.out.println(x+"/"+y);}cin.close();} }

?

總結

以上是生活随笔為你收集整理的ZOJ 3380 Patchouli's Spell Cards——组合数+概率dp的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。