結果
| 問題 | No.170 スワップ文字列(Easy) | 
| コンテスト | |
| ユーザー |  machy | 
| 提出日時 | 2015-06-13 13:05:40 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 922 bytes | 
| コンパイル時間 | 842 ms | 
| コンパイル使用メモリ | 85,988 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-12-23 00:29:31 | 
| 合計ジャッジ時間 | 1,738 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 21 | 
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;
typedef long long LL;
const LL MOD=1000000007;
LL mod_comb(LL n, LL m){
    vector<vector<LL> > dp(n+1, vector<LL>(m+1));
    dp[0][0] = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= m; j++){
            dp[i+1][j] += dp[i][j];
            dp[i+1][j] %= MOD;
        }
        for(int j = 0; j < m; j++){
            dp[i+1][j+1] += dp[i][j];
            dp[i+1][j+1] %= MOD;
        }
    }
    return dp[n][m];
}
int main(){
    string s;
    cin >> s;
    map<int,int> cnt;
    for(int i = 0; i < s.size(); i++){
        cnt[s[i]]++;
    }
    int rest = s.size();
    LL ans = 1;
    for(auto& p : cnt){
        ans *= mod_comb(rest, p.second);
        ans %= MOD;
        rest -= p.second;
    }
    cout << (ans+MOD-1)%MOD << endl;
    return 0;
}
            
            
            
        