Niestety, nie byliśmy w stanie w pełni poprawnie wyświetlić tego pliku, ponieważ nie jest zakodowany w UTF-8.
Możesz pobrać ten plik i spróbować otworzyć go samodzielnie.
#include <iostream> #include <vector> #include <algorithm> #define MOD 1000000007 using namespace std; int main() { int n; int pow2[5001]; int Ld[5001]; pow2[0]=1; for (int i=1;i<5001;++i) { pow2[i]=(2*pow2[i-1])%MOD; Ld[i]=0; } cin >> n; vector<int> a(n); int *S = new int[n]; long long *Ls = new long long[n]; int *kol_d = new int[n]; long long total = 0; for (int i=0;i<n;++i) { cin >> a[i]; Ld[a[i]]++; kol_d[i]=0; } sort(a.begin(),a.end()); if (a[0]>1) { cout << 0 << endl; delete[] S; delete[] Ls; return 0; } S[0]=1; Ls[0]=1; kol_d[0]=1; total = 1; for (int i=1;i<n;++i) { Ls[i]=0; S[i]=a[i]+S[i-1]; if (a[i]==a[i-1]) { Ls[i]=2*Ls[i-1]%MOD; total = (total + Ls[i]) % MOD; kol_d[i]=kol_d[i-1]+1; continue; } kol_d[i]=1; int k=0; for (int j=i-1;j>=0;--j) { if (a[i]<=S[j]+1) { k++; } else break; } if (k==0) break; //+co� z duplikatami if (kol_d[i-k+1]>1) { long long binom = 1; for (int l=Ld[a[i-k]];l>=kol_d[i-k];--l) { Ls[i]+=binom % MOD;//binom(Ld[a[i-k]],l); binom = (binom*l/(Ld[a[i-k]]-l+1)) % MOD; // cout << binom << endl; } Ls[i] = (Ls[i] * pow2[k - 1 - Ld[a[i - k + 1]] + kol_d[i - k]]) % MOD; } else Ls[i]=pow2[k-1]; total = (total + Ls[i]) % MOD; } cout << total << endl; delete[] S; delete[] Ls; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | #include <iostream> #include <vector> #include <algorithm> #define MOD 1000000007 using namespace std; int main() { int n; int pow2[5001]; int Ld[5001]; pow2[0]=1; for (int i=1;i<5001;++i) { pow2[i]=(2*pow2[i-1])%MOD; Ld[i]=0; } cin >> n; vector<int> a(n); int *S = new int[n]; long long *Ls = new long long[n]; int *kol_d = new int[n]; long long total = 0; for (int i=0;i<n;++i) { cin >> a[i]; Ld[a[i]]++; kol_d[i]=0; } sort(a.begin(),a.end()); if (a[0]>1) { cout << 0 << endl; delete[] S; delete[] Ls; return 0; } S[0]=1; Ls[0]=1; kol_d[0]=1; total = 1; for (int i=1;i<n;++i) { Ls[i]=0; S[i]=a[i]+S[i-1]; if (a[i]==a[i-1]) { Ls[i]=2*Ls[i-1]%MOD; total = (total + Ls[i]) % MOD; kol_d[i]=kol_d[i-1]+1; continue; } kol_d[i]=1; int k=0; for (int j=i-1;j>=0;--j) { if (a[i]<=S[j]+1) { k++; } else break; } if (k==0) break; //+co� z duplikatami if (kol_d[i-k+1]>1) { long long binom = 1; for (int l=Ld[a[i-k]];l>=kol_d[i-k];--l) { Ls[i]+=binom % MOD;//binom(Ld[a[i-k]],l); binom = (binom*l/(Ld[a[i-k]]-l+1)) % MOD; // cout << binom << endl; } Ls[i] = (Ls[i] * pow2[k - 1 - Ld[a[i - k + 1]] + kol_d[i - k]]) % MOD; } else Ls[i]=pow2[k-1]; total = (total + Ls[i]) % MOD; } cout << total << endl; delete[] S; delete[] Ls; return 0; } |