对bi取log,则相当于Σbi<=min{bi*ai}。注意到值域很小,那么如果有解,使其成立的最小的Σbi不会很大,大胆猜想不超过Σai。然而一点也不会(xiang)证。暴力枚举就好了。
#include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; #define ll long long #define N 100010 char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;} int gcd(int n,int m){return m==0?n:gcd(m,n%m);} int read() { int x=0,f=1;char c=getchar(); while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();} while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return x*f; } int T,n,a[11]; int main() { #ifndef ONLINE_JUDGE freopen("bzoj5074.in","r",stdin); freopen("bzoj5074.out","w",stdout); const char LL[]="%I64d\n"; #else const char LL[]="%lld\n"; #endif T=read(); while (T--) { n=read();memset(a,0,sizeof(a)); int m=0; for (int i=1;i<=n;i++) { int x=read(); a[x]++;m+=x; } bool flag=0; for (int i=1;i<=m;i++) { ll cnt=0; for (int j=1;j<=10;j++) { cnt+=1ll*a[j]*((i-1)/j+1); if (cnt>i) break; } if (cnt<=i) {flag=1;break;} } if (flag) puts("YES"); else puts("NO"); } return 0; }