Gugu Gu
A. sequence
Where no solution: $ n> a * b $ or $ n <a + b-1 $
The B sequence is divided into segments, each internal rise, fall at the boundary of each segment constituting the sequence.
Implementation is not too easy to think about what the dynamic boundary.
#include<cstdio> #include<iostream> #include<cstring> using namespace std; int T,n,a,b; void work() { scanf("%d%d%d",&n,&a,&b); if(n>1LL*a*b||n<a+b-1) { puts("No"); return ; } puts("Yes"); int beg=n-a+1; for(int i=beg;i<=n;i++) printf("%d ",i); if(b==1)return ; b--; int bl=(beg-1)/b,now=beg-bl; while(b) { bl=(beg-1)/b; now=beg-bl; for(int i=now;i<beg;i++) printf("%d ",i); beg=now; b--; } putchar('\n'); } int main () { scanf("%d",&T); while(T--)work(); return 0; }
B. Shopping
Follow the routine is concerned, the answer should be continuous interval?
It is not. Seeking prefix if the $ A [] $ sort and will find if $ \ frac {a_i} {2}> sum_ {i-1} $, then $ (sum_ {i-1}, \ frac {a_i} { 2}] $ is some gap, because is already sorted, so this gap can not be other ways to make up the.
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; typedef long long ll; const int N=1e5+5; int read() { int x=0,f=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); return x*f; } int n; ll a[N],sum[N],ans; ll div2(ll x) { return (x-1>>1)+1; } int main () { n=read(); for(int i=1;i<=n;i++) a[i]=read(); sort(a+1,a+n+1); for(int i=1;i<=n;i++) { if(div2(a[i])>sum[i-1])ans+=div2(a[i])-sum[i-1]-1; sum[i]=sum[i-1]+a[i]; } cout<<sum[n]-ans<<endl; return 0; }
C. Count
No limit to the number of words is Catalan.
Provided $ dp [l] [r] $ is a section on a pre-order traversing is $ [l, r] $, $ L $ the number of programs to the root of the subtree.
Two-dimensional prefix and record limits, enumeration sub-tree about the size distribution can be transferred.
#include<cstdio> #include<iostream> #include<cstring> using namespace std; int read() { int x=0,f=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); return x*f; } typedef long long ll; const ll mod=1e9+7; const int N=405; int T,n,m,g[N][N],sum[N][N]; ll dp[N][N]; you get (you x, y you, you xx, yy you) { return sum[xx][yy]-sum[x-1][yy]-sum[xx][y-1]+sum[x-1][y-1]; } void work() { n=read();m=read(); memset(g,0,sizeof(g)); memset(sum,0,sizeof(sum)); memset(dp,0,sizeof(dp)); for(int i=1;i<=m;i++) { int x=read(),y=read(); g[x][y]++; } for(int i=1;i<=n;i++) { dp[i][i]=1; for(int j=1;j<=n;j++) sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+g[i][j]; } for (= 2 only, only the <= n, only ++) { for(int i=1;i+len-1<=n;i++) { int j = i + len-1; if(!get(i,i+1,i,j))(dp[i][j]+=dp[i+1][j])%=mod; if(!get(i+1,i,j,i))(dp[i][j]+=dp[i+1][j])%=mod; for(int k=i+1;k<=j-1;k++) if(!get(i,i+1,i,k)&&!get(k+1,i,j,k)) (dp[i][j]+=dp[i+1][k]*dp[k+1][j])%=mod; } } printf("%lld\n",dp[1][n]); return ; } int main () { T=read(); while(T--)work(); return 0; }