# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
57158 | 2018-07-14T07:28:57 Z | 김세빈(#1653) | Skyscraper (JOI16_skyscraper) | C++11 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; const int c = 101010; int D[2][111][3][220202]; int A[111]; int n, k, ans; int main() { int i, j, l, x; scanf("%d%d", &n, &k); for(i=1;i<=n;i++){ scanf("%d", A+i); } if(n == 1){ pritnf("1\n"); return 0; } sort(A+1, A+n+1); for(i=n;i>=1;i--) A[i] -= A[1]; D[0][0][0][0 + c] = 1; for(i=1;i<n;i++){ for(j=0;j<=i;j++){ for(l=-101010;l<=101010;l++){ // endpoints if(j){ D[i&1][j-1][1][l + A[i] + c] = (D[i&1][j-1][1][l + A[i] + c] + D[~i&1][j][0][l + c] * (ll)2) % mod; } D[i&1][j][1][l - A[i] + c] = (D[i&1][j][1][l - A[i] + c] + D[~i&1][j][0][l + c] * (ll)2) % mod; if(j){ D[i&1][j-1][2][l + A[i] + c] = (D[i&1][j-1][2][l + A[i] + c] + D[~i&1][j][1][l + c]) % mod; D[i&1][j-1][1][l + 2*A[i] + c] = (D[i&1][j-1][1][l + 2*A[i] + c] + D[~i&1][j][1][l + c]) % mod; } D[i&1][j][2][l - A[i] + c] = (D[i&1][j][2][l - A[i] + c] + D[~i&1][j][1][l + c]) % mod; D[i&1][j][1][l + c] = (D[i&1][j][1][l + c] + D[~i&1][j][1][l + c]) % mod; if(j){ D[i&1][j-1][2][l + 2*A[i] + c] = (D[i&1][j-1][2][l + 2*A[i] + c] + D[~i&1][j][2][l + c] * (ll)2) % mod; } D[i&1][j][2][l + c] = (D[i&1][j][2][l + c] + D[~i&1][j][2][l + c] * (ll)2) % mod; for(x=0;x<3;x++){ // new group D[i&1][j+1][x][l - 2*A[i] + c] = (D[i&1][j+1][x][l - 2*A[i] + c] + D[~i&1][j][x][l + c] * (ll)(j + 1)) % mod; // merge two groups if(j > 1){ D[i&1][j-1][x][l + 2*A[i] + c] = (D[i&1][j-1][x][l + 2*A[i] + c] + D[~i&1][j][x][l + c] * (ll)(j - 1)) % mod; } // group endpoints D[i&1][j][x][l + c] = (D[i&1][j][x][l + c] + D[~i&1][j][x][l + c] * (ll)2 * j) % mod; D[~i&1][j][x][l + c] = 0; } } } } for(l=-101010;l<=101010;l++){ if(0 <= l + A[n] * 2 && l + A[n] * 2 <= k) ans = (ans + D[~n&1][0][2][l + c]) % mod; if(0 <= l + A[n] && l + A[n] <= k) ans = (ans + D[~n&1][0][1][l + c]) % mod; } printf("%d\n", ans); return 0; }