首頁 資料庫 mysql教程 Topcoder srm 653 div.2 500

Topcoder srm 653 div.2 500

Jun 07, 2016 pm 03:44 PM
500

题意: 两个人玩石头剪刀布,你知道对方每次要出什么,有n(1~2000)局, 每局如果你赢了得1分,否则不得分,问你拿到某个分 score (0~2000)的方案数有多少。 0:石头, 1:布, 2:剪刀. 思路: 一开始想到的是组合数学的方法.每一局得分的情况只有一个,但是不得分的

题意:

两个人玩石头剪刀布,你知道对方每次要出什么,有n(1~2000)局, 每局如果你赢了得1分,否则不得分,问你拿到某个分值score(0~2000)的方案数有多少。0:石头, 1:布, 2:剪刀.

思路:

一开始想到的是组合数学的方法.每一局得分的情况只有一个,但是不得分的情况有两个,所以是任选score局*2...

但是要mod(1e9+7), 除数用mod, 要用逆元..

AC.

    #line 7 "RockPaperScissorsMagicEasy.cpp"
    #include <cstdlib>
    #include <cctype>
    #include <cstring>
    #include <cstdio>
    #include <cmath>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <iostream>
    #include <sstream>
    #include <map>
    #include <set>
    #include <queue>
    #include <stack>
    #include <fstream>
    #include <numeric>
    #include <iomanip>
    #include <bitset>
    #include <list>
    #include <stdexcept>
    #include <functional>
    #include <utility>
    #include <ctime>

    using namespace std;

    #define PB push_back
    #define MP make_pair

    #define REP(i,n) for(i=0;i=(l);--i)

    typedef vector<int> VI;
    typedef vector<string> VS;
    typedef vector<double> VD;
    typedef int LL;
    typedef pair<int> PII;
    typedef long long ll;

    class RockPaperScissorsMagicEasy
    {
            public:
            ll fact[2005];
            const int mod = 1e9+7;
            RockPaperScissorsMagicEasy()
            {
                fact[0]=1;
                for(int i=1;i e2+e3) return 0;
                return a1*mod_inverse(a2*a3%p,p)%p;
            }
            ll extgcd(ll a,ll b,ll &x,ll &y)
            {
                ll d=a;
                if(b)
                {
                    d=extgcd(b,a%b,y,x);
                    y-=(a/b)*x;
                }
                else
                {
                    x=1;y=0;
                }
                return d;
            }
            ll mod_inverse(ll a,ll m)
            {
                ll  x,y;
                extgcd(a,m,x,y);
                return (m+x%m)%m;
            }
            ll mod_pow(ll a,ll n)
            {
                ll ans=1,b=a;
                while(n)
                {
                    if(n&1) ans=ans*b%mod;
                    n>>=1;
                    b=b*b%mod;
                }
                return ans;
            }

            int count(vector <int> card, int score)
            {
                int t = card.size();
                //printf("%d\n", t);
                if(score > t) return 0;
                if(score == t) return 1;
                if(score == 0) {
                    return t*2;
                }
                int ans=modc(t,score,mod)*mod_pow(2,t-score)%mod;
                return ans;
            }</int></int></double></string></int></ctime></utility></functional></stdexcept></list></bitset></iomanip></numeric></fstream></stack></queue></set></map></sstream></iostream></string></vector></algorithm></cmath></cstdio></cstring></cctype></cstdlib>
登入後複製


第二种方法是DP.

dp[i][j]: 表示第i局中有j局得分的方案数. dp[i][j] = (dp[i-1][j] + dp[i-1][j-1]) % mod

AC.

  #line 7 "RockPaperScissorsMagicEasy.cpp"
    #include <cstdlib>
    #include <cctype>
    #include <cstring>
    #include <cstdio>
    #include <cmath>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <iostream>
    #include <sstream>
    #include <map>
    #include <set>
    #include <queue>
    #include <stack>
    #include <fstream>
    #include <numeric>
    #include <iomanip>
    #include <bitset>
    #include <list>
    #include <stdexcept>
    #include <functional>
    #include <utility>
    #include <ctime>

    using namespace std;

    #define PB push_back
    #define MP make_pair

    #define REP(i,n) for(i=0;i=(l);--i)

    typedef vector<int> VI;
    typedef vector<string> VS;
    typedef vector<double> VD;
    typedef long long ll;
    typedef pair<int> PII;

    class RockPaperScissorsMagicEasy
    {
            public:
            ll dp[2005][2005];
            ll cal(ll a, ll n, ll mod)
            {
                ll s = 1;
                while(n > 0) {
                    if(n&1) s = s*a%mod;
                    a = a*a%mod;
                    n >>= 1;
                }
                return s;
            }
            int count(vector <int> card, int score)
            {
                int len = card.size();
                ll mod = 1e9+7;
                if(len <br>
<br>



</int></int></double></string></int></ctime></utility></functional></stdexcept></list></bitset></iomanip></numeric></fstream></stack></queue></set></map></sstream></iostream></string></vector></algorithm></cmath></cstdio></cstring></cctype></cstdlib>
登入後複製
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

<🎜>:泡泡膠模擬器無窮大 - 如何獲取和使用皇家鑰匙
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
北端:融合系統,解釋
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆樹的耳語 - 如何解鎖抓鉤
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

Java教學
1666
14
CakePHP 教程
1426
52
Laravel 教程
1328
25
PHP教程
1273
29
C# 教程
1253
24
500internal server error什麼意思 500internal server error什麼意思 Feb 21, 2023 pm 03:39 PM

500internal server error的意思是HTTP 500內部伺服器錯誤,表示伺服器遇到意外情況,導致其無法履行請求,但它無法說明具體錯誤或發生錯誤的根本原因;當發生錯誤時,造訪的網站會顯示發生錯誤。

敦促英國人在家檢查是否有稀有的 50 便士硬幣,可能價值 2,500 英鎊 敦促英國人在家檢查是否有稀有的 50 便士硬幣,可能價值 2,500 英鎊 Oct 28, 2024 pm 04:20 PM

據一位專家稱,這枚 2011 年的作品是為慶祝 2012 年倫敦奧運會而鑄造的

以太坊 (ETH) 價格恢復至 2,320 美元上方,但仍難以加快步伐 以太坊 (ETH) 價格恢復至 2,320 美元上方,但仍難以加快步伐 Sep 10, 2024 pm 03:20 PM

以太幣價格在 2,250 美元上方開始復甦浪潮。 ETH 能夠清除 2,280 美元的阻力區,進入積極區域,但與比特幣相比,勢頭較弱。

比特幣 (BTC) 價格分析:BTC 開始大幅上漲,目標為 6 萬美元大關 比特幣 (BTC) 價格分析:BTC 開始大幅上漲,目標為 6 萬美元大關 Sep 12, 2024 pm 06:35 PM

比特幣已經開始大幅上漲,突破了 57,500 美元的阻力位,現在顯示出可能達到 60,000 美元大關的良好跡象。

BetMGM 密西根州獎金代碼 MLIVEMGM:獲得 1,500 美元的首次投注優惠 BetMGM 密西根州獎金代碼 MLIVEMGM:獲得 1,500 美元的首次投注優惠 Nov 18, 2024 am 03:36 AM

新玩家可以使用促銷代碼 MLIVEMGM 領取 BetMGM 歡迎獎金,並獲得高達 1,500 美元的獎金投注返還。

英國人敦促檢查他們的 50 便士硬幣,因為稀有版本可能價值 2500 英鎊 英國人敦促檢查他們的 50 便士硬幣,因為稀有版本可能價值 2500 英鎊 Oct 28, 2024 pm 04:24 PM

2011 年硬幣是為慶祝 2012 年倫敦奧運會而鑄造的,被稱為“水上運動”設計,並帶有游泳運動員的形象

Rexas Finance (RXS):Solana (SOL) 和以太坊 (ETH) 的潛在競爭對手 Rexas Finance (RXS):Solana (SOL) 和以太坊 (ETH) 的潛在競爭對手 Nov 04, 2024 pm 06:44 PM

在這場永無止境的區塊鏈技術競賽中,有兩項技術脫穎而出並吸引了投資者的注意:Solana (SOL) 和以太坊 (ETH)。

Solana 價格可能達到 4,500 美元 Solana 價格可能達到 4,500 美元 Oct 22, 2024 am 06:42 AM

SOL 在其周線圖上形成了杯柄形態,這表明 Solana 價格可能飆升 2,600%,升至 4,500 美元。

See all articles