Shanghai 2019 J

First, meaning of the questions can be obtained, the A 'may be removed so that any t A'-t <= A and A'> = A-A ', i.e. A' of the smallest stones removed in

Make the first 01 backpack is no possibility to find out the meaning of problems limit

Then back Backpacks possibility of the smallest stones from the heap A 'was removed to give the possibility to the minimum all the A smallest stones apos

#include <cstdio>
#include <cmath>
#include <algorithm>

typedef long long ll;
using namespace std;
const ll mod = 1e9+7;
const int maxn = 300;
const int maxm = 500;
int dp[maxn*maxm+10];
int a[maxn];
int main () {
    int t, n;
    scanf("%d", &t);
    while (t--) {
        scanf("%d", &n);
        int s = 0;
        for (int i = 0; i < n; i++)
            scanf("%d", &a[i]), s += a[i];
        sort(a, a+n);
        for (int i = 0; i <= s; i++) dp[i] = 0;
        dp[0] = 1;
        for (int i = 0; i < n; i++) {
            for( Int J = S; J> = A [I]; J, ) { 
                DP [J] + DP = [J- A [I]]; 
                DP [J] % = MOD; 
            } 
        } // 01 backpack 
        ll ANS = 0 ;
         for ( int I = 0 ; I <n-; I ++ ) {
             // . ascending back backpack that the smallest stones t constantly updated to a [I] 
            for ( int J = a [I]; J < S =; J ++ ) 
                DP [J] = (DP [J] - DP [JA [I]] + MOD)% MOD;
             // enumeration T-A' 
            for ( int j = max((s+1)/2-a[i], 0); j <= s-j-a[i]; j++)
                ans = (ans+dp[j]) % mod;
        }
        printf("%lld\n", ans);
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/Urchin-C/p/11531203.html