[洛谷] P1866 编号

简单递推 乘的时候要减去前面数字的个数 因为会重复

//#pragma GCC optimize(2)
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;

const int MAXN = 1e6 + 10;

int arr[MAXN] = {0};

const int MOD = 1e9 + 7;

int main()
{
    //ios::sync_with_stdio(false);

    //cin.tie(0);     cout.tie(0);

    int len;

    cin>>len;

    for(int i = 0; i < len; i++)
        cin>>arr[i];

    sort(arr, arr + len);

    ll ans = arr[0];

    for(int i = 1; i < len; i++)
        ans = (ans * (arr[i] - i) ) % MOD;

    cout<<ans<<endl;

    return 0;
}

递推

posted @ 2018-09-25 16:32  张浦  阅读(98)  评论(0编辑  收藏  举报