Luogu T103187 涓滄柟CannonBall 姒傜巼dp
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Luogu T103187 涓滄柟CannonBall 姒傜巼dp相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/marked' title='marked'>marked ann col 鎵嬫満 show algorithm 绛旀 names
棰樼洰鑳屾櫙
涓滄柟CannonBall锛堣瘧鍚嶄笢鏂瑰ぇ鐐脊锛夋槸杩戞湡鍙戝竷鐨勭涓€娆捐幏寰梈UN鎺堟潈鐨勫晢涓氫笢鏂逛簩娆″垱浣滄墜鏈烘父鎴忥紝娓告垙鍏冲崱涓帺瀹跺湪绫讳技澶у瘜缈佺殑妫嬬洏涓婁笌CPU鎴栨槸鐜╁杩涜瀵规垬銆?/p>
棰樼洰鎻忚堪
鍦ㄦ父鎴忎腑锛屾瘡浣嶇帺瀹舵嫢鏈夎嫢骞蹭釜鍏潰楠板瓙銆傚綋涓ゅ悕鐜╁鐩搁亣鏃讹紝灏嗕細閫氳繃鎺峰嚭鎵€鏈夐瀛愮殑鏂瑰紡鍒ゅ畾鑳滆礋銆備綘鎷ユ湁xx涓瀛愶紝鑰屼綘鐨勫鎵嬫嫢鏈?span class="katex">yy涓瀛愶紝璇烽棶浣犺儨鐜囷紝鍗充綘鐨勭偣鏁板拰澶т簬瀵规墜鐨勬鐜囨槸澶氬皯锛?/span>
姝e紡鍦拌锛屽皢鐜╁鐨?span class="katex">nn涓瀛愮紪鍙蜂负1..n1..n锛屽湪姣忔鎺烽瀛愭椂锛岀ii涓瀛愮殑鐐规暟a_iai?浼氬湪{1,2,3,4,5,6}{1,2,3,4,5,6}涓瓑姒傜巼闅忔満閫夊彇锛岀帺瀹剁殑鐐规暟鍜?span class="katex">C_n=sum_{1le i le n} a_iCn?=∑1≤i≤n?ai?锛屾眰P(C_x>C_y)P(Cx?>Cy?)
杈撳叆鏍煎紡
涓€琛?涓暣鏁帮紝渚濇琛ㄧず浣犵殑楠板瓙鏁?span class="katex">xx鍜屽鎵嬬殑楠板瓙鏁?span class="katex">yy銆?/span>
杈撳嚭鏍煎紡
涓€琛屼竴涓櫨鍒嗘暟锛屽洓鑸嶄簲鍏ヤ繚鐣欏皬鏁扮偣鍚?浣嶅皬鏁帮紝琛ㄧず浣犵殑鑳滅巼銆?/p>
杈撳叆杈撳嚭鏍蜂緥
1 1
41.67%
500 499
52.22%
璇存槑/鎻愮ず
瀵逛簬鏍蜂緥1锛屽弻鏂规湁frac {1} {6}61?鐨勬鐜囨幏鍑虹浉鍚屽€硷紝鍏朵粬鎯呭喌涓嬭緭璧㈠悇鍗犱竴鍗婏紝鏁呯瓟妗堜负frac {5} {12}125?
鏈浣跨敤鏂囨湰鏂瑰紡姣旇緝
鏁版嵁瑙勬ā
瀵逛簬 30\%30% 鐨勬暟鎹紝淇濊瘉 x+y le 8x+y≤8銆?/span>
瀵逛簬 60\%60% 鐨勬暟鎹紝淇濊瘉 x,y le 10x,y≤10
瀵逛簬 100\%100% 鐨勬暟鎹紝淇濊瘉 1 le x, yleq 10001≤x,y≤1000
鍋氭硶濡傞銆?00鍒嗙洰娴嬮渶瑕佸姞楂樼簿搴︼紙+ × / 杩愮畻锛?/span>
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 6 using namespace std; 7 typedef long long ll; 8 9 ll read(){ 10 ll a = 0; char l = 鈥?/span> 鈥?/span>,c = getchar(); 11 while(c < 鈥?/span>0鈥?/span>||c > 鈥?/span>9鈥?/span>)l = c,c = getchar(); 12 while(鈥?/span>0鈥?/span> <= c&&c <= 鈥?/span>9鈥?/span>)a = a*10+c-鈥?/span>0鈥?/span>,c = getchar(); 13 if(l == 鈥?/span>-鈥?/span>)return -a; return a; 14 } 15 16 ll f[2][2][6010],s[2][6010]; 17 ll x,y,win,tot; 18 19 int main(){ 20 x = read(),y = read(); 21 // for(int i = 1;i <= 6;i++)f[0][0][i] = f[0][1][i] = 1; 22 f[0][0][0] = f[0][1][0] = 1; 23 for(int i = 1;i <= x;i++){ 24 memset(f[i&1][0],0,sizeof(f[i&1][0])); 25 for(int j = x*6;j >= 0;j--)if(f[~i&1][0][j]) 26 for(int k = 1;k <= 6;k++) 27 f[i&1][0][j+k] += f[~i&1][0][j]; 28 } 29 for(int i = 1;i <= y;i++){ 30 memset(f[i&1][1],0,sizeof(f[i&1][1])); 31 for(int j = y*6;j >= 0;j--)if(f[~i&1][1][j]){ 32 // printf("%d ",f[~i&1][1][j]); 33 for(int k = 1;k <= 6;k++) 34 f[i&1][1][j+k] += f[~i&1][1][j]; 35 }//putchar(鈥榎n鈥?; 36 } 37 // for(int i = 1;i <= x*6;i++) 38 // s[0][i] = s[0][i-1]+f[0][i]; 39 // for(int i = 1;i <= y*6;i++) 40 // s[1][i] = s[1][i-1]+f[y&1][1][i]; 41 for(int i = x;i <= x*6;i++){ 42 ll cur = 0; 43 for(int j = y;j < i;j++)cur += f[x&1][0][i]*f[y&1][1][j]; 44 win += cur; 45 for(int j = i;j <= y*6;j++)cur += f[x&1][0][i]*f[y&1][1][j]; 46 tot += cur; 47 } 48 49 // cout << win << 鈥?鈥?<< tot << endl; 50 // for(int i = 0;i <= x*6;i++)printf("%d ",f[x&1][0][i]);putchar(鈥榎n鈥?; 51 // for(int i = 0;i <= y*6;i++)printf("%d ",f[y&1][1][i]);putchar(鈥榎n鈥?; 52 53 double ans = 1.0*win/tot*100; 54 printf("%.2f%%",ans); 55 return 0; 56 }
以上是关于Luogu T103187 涓滄柟CannonBall 姒傜巼dp的主要内容,如果未能解决你的问题,请参考以下文章