NCD 2019

http://codeforces.com/gym/102163
待更新。。。ABEGJ

C. Hasan and his lazy students

time limit per test4.0 s
memory limit per test256 MB
inputstandard input
outputstandard output
Hasan is teaching Dynamic Programming to his students at NCD. However, he feels they aren’t studying what he is giving them, so he decided to test them on the NCDPC. He will give them an array of length N, and they must tell him how many Longest Increasing Subsequences are in the array.

For example, if the array is (1 2 1 4 3). The LIS’s length is 3, and it could be (1 2 4) or (1 2 3), so the answer is 2. Note that you can’t choose (1 1 3) because it must be a strictly increasing subsequence, and you can’t choose (1 2 3 4) because you can’t change the order of a subsequence.

Input
First line of the input will be T, number of test cases.

Each test case starts with N, the size of the array, next line contain N space separated integers, the array.

1≤N≤1000,1≤Ai≤106
Output
For each test case print one line, the length of the LIS and the number of LISes. As this number may be very large, print it module 109+7
Example
inputCopy
3
5
1 3 2 3 1
3
1 2 3
7
1 5 6 2 1 4 1
outputCopy
3 1
3 1
3 2


题意:求最长上升子序列的个数

代码:
#include 
#include 
#include 
#define ll long long

using namespace std;
const int mod = 1e9+7;
const int N = 1010;
const int maxn = 1e6+100;

ll sum[N][N];//表示以i结尾,长度为j的上升子序列的总个数
int dp[N];// 表示以i结尾的最长上升子序列的长度
int a[N];

int main()
{
    int t, n;
    cin >> t;
    while(t--)
    {
        scanf("%d",&n);
        memset(sum,0,sizeof(sum));
        int maxlen=1;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            dp[i]=1;
            sum[i][1]=1ll;
            for(int j=0;j<i;j++)
            {
                if(a[j]<a[i])
                {
                    dp[i]=max(dp[i],dp[j]+1);//取最大长度
                    sum[i][dp[j]+1]=(sum[i][dp[j]+1]+sum[j][dp[j]])%mod;
                    maxlen=max(maxlen,dp[i]);
                }
            }
        }
        ll res=0;
        for(int i=0;i<n;i++)
        {
            res=(res+sum[i][maxlen])%mod;
        }
        cout << maxlen << " " << res << endl;
    }
    return 0;
}

你可能感兴趣的:(cf-gym)