看到题目的第一眼就感到十分熟悉。。。后来才发现是半年前心血来潮(一时脑残)打CF现场赛时的题目。。。当时果真的太弱了。。这种题目都不会做。。。
其实是很简单的记忆化搜索。。枚举子树的大小考虑一下限制什么的乱搞(口胡)一下就好了。。
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int mod = 1e9+7; int a[510],n,vis[510][510],f[510][510]; int read(){ int x = 0,f = 1,c = getchar(); while (c<'0' || c>'9'){if (c=='-') f = -1;c = getchar();} while (c>='0' && c<='9') x = x*10+c-'0',c = getchar(); return x*f; } int dfs(int l,int r){ if (l>r) return f[l][r] = 1; if (f[l][r]) return f[l][r]; int res = dfs(l+1,r),pos = r; for (int i=l;i<r;i++) if (a[l]<a[i+1]) (res+=1ll*dfs(l+1,i)*dfs(i+1,r)%mod)%=mod; return f[l][r] = res%mod; } int main(){ // freopen("tree.in","r",stdin); // freopen("tree.out","w",stdout); n = read(); for (int i=1;i<=n;i++) a[i] = read(); printf("%d",dfs(2,n)); }
2022年5月23日 20:33
If it is been a bit since the house has also been professionally wiped clean or if it is never also been professionally cleaned a Deep Cleaning is things to get you started off on the suitable foot. We escape our finest and the majority precise tools for our deep cleanings. We guarantee that dust bunny is taken out, every space and cranny is usually wiped fresh and the many hard to realize places pick up the time period and care needed. Your home will likely be as clean in any other case cleaner when you do you migrated in!