Submission #1835126
Source Code Expand
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<algorithm> using namespace std; const int N=309; const int mod=1000000007; int n,ans,i2; int dp[N][N][N*2],d[N],fac[N],inv[N]; int quickpow(int x,int y){ int s=1; for (;y;y>>=1,x=1ll*x*x%mod) if (y&1) s=1ll*s*x%mod; return s; } void init(){ int i; fac[0]=fac[1]=inv[0]=inv[1]=1; for (i=2;i<=n+n;i++) fac[i]=1ll*fac[i-1]*i%mod; inv[n+n]=quickpow(fac[n+n],mod-2); for (i=n+n-1;i;i--) inv[i]=1ll*inv[i+1]*(i+1)%mod; } void add(int &x,int y){ x+=y; (x>=mod)?x-=mod:0; } int main(){ int i,j,k; scanf("%d",&n); for (i=0;i<n;i++) scanf("%d",&d[i]); init(); dp[0][0][0]=1; for (i=0;i<n;i++) for (j=0;j<=i;j++) for (k=0;k<=n+n;k++){ if (!dp[i][j][k]) continue; add(dp[i+1][j][k],1ll*dp[i][j][k]*inv[d[i]-1]%mod); if (d[i]>=2) add(dp[i+1][j+1][k+d[i]-2],1ll*dp[i][j][k]*inv[d[i]-2]%mod); } i2=quickpow(2,mod-2); for (j=3;j<=n;j++) for (k=0;k<=n+n;k++){ if (!dp[n][j][k]) continue; if (j<n&&k==0) continue; if (j==n&&k==0){ add(ans,1ll*dp[n][j][k]*i2%mod*fac[n-1]%mod); continue; } if (j<n) add(ans,1ll*dp[n][j][k]*k%mod*fac[j-1]%mod*fac[n-j-1]%mod*i2%mod); } printf("%d\n",ans); return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Unicyclic Graph Counting |
User | wdyhy |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 1312 Byte |
Status | RE |
Exec Time | 98 ms |
Memory | 112896 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:37:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&n); ^ ./Main.cpp:38:37: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] for (i=0;i<n;i++) scanf("%d",&d[i]); ^
Judge Result
Set Name | Sample | Subtask1 | Subtask2 | Subtask3 | All | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 200 / 200 | 200 / 200 | 300 / 300 | 0 / 300 | ||||||||||||
Status |
|
|
|
|
|
Set Name | Test Cases |
---|---|
Sample | 00_example_01.txt, 00_example_02.txt |
Subtask1 | 00_example_01.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s1_08.txt |
Subtask2 | 00_example_01.txt, 00_example_02.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s1_08.txt, s2_09.txt, s2_10.txt, s2_11.txt, s2_12.txt, s2_13.txt, s2_14.txt, s2_15.txt, s2_16.txt |
Subtask3 | 00_example_01.txt, 00_example_02.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s1_08.txt, s2_09.txt, s2_10.txt, s2_11.txt, s2_12.txt, s2_13.txt, s2_14.txt, s2_15.txt, s2_16.txt, s3_17.txt, s3_18.txt, s3_19.txt, s3_20.txt, s3_21.txt, s3_22.txt, s3_23.txt, s3_24.txt, s3_25.txt, s3_26.txt |
All | 00_example_01.txt, 00_example_02.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s1_08.txt, s2_09.txt, s2_10.txt, s2_11.txt, s2_12.txt, s2_13.txt, s2_14.txt, s2_15.txt, s2_16.txt, s3_17.txt, s3_18.txt, s3_19.txt, s3_20.txt, s3_21.txt, s3_22.txt, s3_23.txt, s3_24.txt, s3_25.txt, s3_26.txt, s4_27.txt, s4_28.txt, s4_29.txt, s4_30.txt, s4_31.txt, s4_32.txt, s4_33.txt, s4_34.txt, s4_35.txt, s4_36.txt, s4_37.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_example_01.txt | AC | 2 ms | 2304 KB |
00_example_02.txt | AC | 3 ms | 10496 KB |
s1_01.txt | AC | 2 ms | 2304 KB |
s1_02.txt | AC | 2 ms | 2304 KB |
s1_03.txt | AC | 2 ms | 2304 KB |
s1_04.txt | AC | 2 ms | 2304 KB |
s1_05.txt | AC | 2 ms | 2304 KB |
s1_06.txt | AC | 2 ms | 2304 KB |
s1_07.txt | AC | 2 ms | 2304 KB |
s1_08.txt | AC | 2 ms | 2304 KB |
s2_09.txt | AC | 3 ms | 10496 KB |
s2_10.txt | AC | 3 ms | 12544 KB |
s2_11.txt | AC | 4 ms | 12544 KB |
s2_12.txt | AC | 4 ms | 12544 KB |
s2_13.txt | AC | 4 ms | 12544 KB |
s2_14.txt | AC | 4 ms | 12544 KB |
s2_15.txt | AC | 4 ms | 12544 KB |
s2_16.txt | AC | 3 ms | 12544 KB |
s3_17.txt | AC | 6 ms | 26880 KB |
s3_18.txt | AC | 6 ms | 26880 KB |
s3_19.txt | AC | 7 ms | 28928 KB |
s3_20.txt | AC | 6 ms | 24832 KB |
s3_21.txt | AC | 4 ms | 14592 KB |
s3_22.txt | AC | 8 ms | 37120 KB |
s3_23.txt | AC | 9 ms | 37120 KB |
s3_24.txt | AC | 8 ms | 37120 KB |
s3_25.txt | AC | 8 ms | 37120 KB |
s3_26.txt | AC | 8 ms | 37120 KB |
s4_27.txt | AC | 27 ms | 112896 KB |
s4_28.txt | AC | 16 ms | 71936 KB |
s4_29.txt | RE | 96 ms | 256 KB |
s4_30.txt | AC | 21 ms | 90368 KB |
s4_31.txt | RE | 97 ms | 256 KB |
s4_32.txt | RE | 97 ms | 256 KB |
s4_33.txt | RE | 98 ms | 256 KB |
s4_34.txt | RE | 96 ms | 256 KB |
s4_35.txt | RE | 97 ms | 256 KB |
s4_36.txt | RE | 98 ms | 256 KB |
s4_37.txt | RE | 96 ms | 256 KB |