noip模拟72(待补)
作者:互联网
T1 出了个大阴间题
状压 \(dp\),设 \(f_{s,k}\) 表示 \(s\) 状态下,当前的 \(max_a -\) 最大值等于 \(j\) 的所有代价.
有一个不会对分数有什么影响的规律,就是 \(k\) 永远 \(\le 1\).
A_code
#include<bits/stdc++.h>
using namespace std;
namespace BSS {
#define ll long long
#define ull unsigned ll
#define lf long double
#define lbt(x) (x&(-x))
#define mp(x,y) make_pair(x,y)
#define lb lower_bound
#define ub upper_bound
#define Fill(x,y) memset(x,y,sizeof x)
#define Copy(x,y) memcpy(x,y,sizeof x)
#define File(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
inline ll read() {
ll w=0; bool cit=1; char ch;
while(!isdigit(ch=getchar())) if(ch=='-') cit=0;
while(isdigit(ch)) w=(w<<3)+(w<<1)+(ch^48),ch=getchar();
return cit?w:-w;
}
} using namespace BSS;
const ll mod=1e9+7;
ll m,n,U,maxval;
ll val[25],b[25];
ll num[1<<18];
map<ll,ll> f[1<<18],g[1<<18];
signed main(){
File(repair);
n=read(),m=read()%mod,U=(1<<n)-1;
for(ll i=1;i<=n;i++) val[i]=read();
for(ll i=2;i<=n;i++) b[i]=b[i-1]<<1|1;
for(ll i=1;i<=n;i++) f[1<<i-1][val[i]]=0,g[1<<i-1][val[i]]++;
for(ll i=1;i<U;i++){
num[i]=num[i&(i-1)]+1;
for(ll j=1,k;j<=n;j++){
if((i>>j-1)&1) continue; k=i|(1<<j-1);
for(auto c : f[i]){
ll to=(c.first==val[j] ? val[j]+1 : max(c.first,val[j]));
f[k][to]=(f[k][to]+f[i][c.first]+(to*m%mod+b[num[i]])%mod*g[i][c.first]%mod)%mod;
g[k][to]=(g[k][to]+g[i][c.first])%mod;
}
}
}
for(auto i : f[U]) maxval=max(maxval,i.first);
printf("%lld %lld\n",maxval,f[U][maxval]%mod),exit(0);
}
T2 最简单辣快来做
自以为是打的是正解,其实连别人的暴力都不如.
自以为把简单的想复杂就可能是正解,像个笑话.
正解是利用分块思想,考虑把每个横纵坐标都有当成一条线,于是变成了 \(n^2\) 个矩形.
然后前缀和即可.
学习了光速幂.
B_code
#include<bits/stdc++.h>
using namespace std;
namespace BSS {
#define ll long long
#define ull unsigned ll
#define lf long double
#define lbt(x) (x&(-x))
#define mp(x,y) make_pair(x,y)
#define lb lower_bound
#define ub upper_bound
#define Fill(x,y) memset(x,y,sizeof x)
#define Copy(x,y) memcpy(x,y,sizeof x)
#define File(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
inline ll read() {
ll w=0; bool cit=1; char ch;
while(!isdigit(ch=getchar())) if(ch=='-') cit=0;
while(isdigit(ch)) w=(w<<3)+(w<<1)+(ch^48),ch=getchar();
return cit?w:-w;
}
} using namespace BSS;
const ll N=2e3+21,W=1e5;
ll m,n,s,ops,mod,cntx,cnty;
ll lshx[N],lshy[N];
ll rk[N][N];
ll pre[5][N][N];
struct I { ll x,y,h,id; } p[N*100];
struct Flash_Pow{
ll val; ll sm[W+21],bg[W+21],po[N];
inline void Pre(){
sm[0]=1; for(ll i=1;i<=W;i++) sm[i]=sm[i-1]*val%mod;
bg[0]=1; for(ll i=1;i<=W;i++) bg[i]=bg[i-1]*sm[W]%mod;
}
inline ll qpow(ll x){ return sm[x%W]*bg[x/W]%mod; }
} A,B;
signed main(){
File(satellite);
s=read(),ops=read(),n=read(),m=read(); ll x,y,res;
mod=read(),A.val=read(),B.val=read(),A.Pre(),B.Pre();
for(ll i=1;i<=s;i++){
p[i].h=read()%mod,p[i].id=i;
lshx[++cntx]=(p[i].x=read()),lshy[++cnty]=(p[i].y=read());
}
sort(lshx+1,lshx+1+cntx),cntx=unique(lshx+1,lshx+1+cntx)-lshx-1;
sort(lshy+1,lshy+1+cnty),cnty=unique(lshy+1,lshy+1+cnty)-lshy-1;
for(ll i=1;i<=cntx;i++) A.po[i]=A.qpow(lshx[i]-lshx[i-1]);
for(ll i=1;i<=cnty;i++) B.po[i]=B.qpow(lshy[i]-lshy[i-1]);
for(ll i=1;i<=s;i++){
p[i].x=lb(lshx+1,lshx+1+cntx,p[i].x)-lshx,p[i].y=lb(lshy+1,lshy+1+cnty,p[i].y)-lshy;
rk[p[i].x][p[i].y]=p[i].id;
pre[1][p[i].x][p[i].y]+=p[i].h,pre[2][p[i].x][p[i].y]+=p[i].h;
pre[3][p[i].x][p[i].y]+=p[i].h,pre[4][p[i].x][p[i].y]+=p[i].h;
}
for(ll i=1;i<=cntx;i++){
for(ll j=1;j<=cnty;j++){
y=pre[1][i][j]%mod;
y=(y+pre[1][i-1][j]*A.po[i]%mod+pre[1][i][j-1]*B.po[j]%mod)%mod;
y=(y-pre[1][i-1][j-1]*A.po[i]%mod*B.po[j]%mod+mod)%mod,pre[1][i][j]=y;
}
for(ll j=cnty;j>=1;j--){
y=pre[2][i][j]%mod;
y=(y+pre[2][i-1][j]*A.po[i]%mod+pre[2][i][j+1]*B.po[j+1]%mod)%mod;
y=(y-pre[2][i-1][j+1]*A.po[i]%mod*B.po[j+1]%mod+mod)%mod,pre[2][i][j]=y;
}
}
for(ll i=cntx;i>=1;i--){
for(ll j=1;j<=cnty;j++){
y=pre[3][i][j]%mod;
y=(y+pre[3][i+1][j]*A.po[i+1]%mod+pre[3][i][j-1]*B.po[j]%mod)%mod;
y=(y-pre[3][i+1][j-1]*A.po[i+1]%mod*B.po[j]%mod+mod)%mod,pre[3][i][j]=y;
}
for(ll j=cnty;j>=1;j--){
y=pre[4][i][j]%mod;
y=(y+pre[4][i+1][j]*A.po[i+1]%mod+pre[4][i][j+1]*B.po[j+1]%mod)%mod;
y=(y-pre[4][i+1][j+1]*A.po[i+1]%mod*B.po[j+1]%mod+mod)%mod,pre[4][i][j]=y;
}
}
while(ops--){
x=read(),y=read(),res=0;
ll i=ub(lshx+1,lshx+1+cntx,x)-lshx-1,j=ub(lshy+1,lshy+1+cnty,y)-lshy-1;
res=(res+pre[1][i][j]*A.qpow(abs(x-lshx[i]))%mod*B.qpow(abs(y-lshy[j]))%mod)%mod;
res=(res+pre[2][i][j+1]*A.qpow(abs(x-lshx[i]))%mod*B.qpow(abs(y-lshy[j+1]))%mod)%mod;
res=(res+pre[3][i+1][j]*A.qpow(abs(x-lshx[i+1]))%mod*B.qpow(abs(y-lshy[j]))%mod)%mod;
res=(res+pre[4][i+1][j+1]*A.qpow(abs(x-lshx[i+1]))%mod*B.qpow(abs(y-lshy[j+1]))%mod)%mod;
printf("%lld\n",res);
}
exit(0);
}
T3 是我的你不要抢
\(Hash\) 能水过.
正解还没打.
C_code
#include<bits/stdc++.h>
using namespace std;
namespace BSS {
#define ll int
#define ull unsigned ll
#define lf long double
#define lbt(x) (x&(-x))
#define mp(x,y) make_pair(x,y)
#define lb lower_bound
#define ub upper_bound
#define Fill(x,y) memset(x,y,sizeof x)
#define Copy(x,y) memcpy(x,y,sizeof x)
#define File(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
inline ll read() {
ll w=0; bool cit=1; char ch;
while(!isdigit(ch=getchar())) if(ch=='-') cit=0;
while(isdigit(ch)) w=(w<<3)+(w<<1)+(ch^48),ch=getchar();
return cit?w:-w;
}
} using namespace BSS;
const ll N=6e5+21;
const ull P=131;
ll m,n,ops,maxlen,ans;
ll len[N];
ull po[N];
vector<ull> c[N],pre[N];
unordered_map<ll,ll> mp1[N];
inline ull getsh(ll x,ll l,ll r){ return pre[x][r]-pre[x][l-1]*po[r-l+1]; }
signed main(){
File(string);
n=read(),ops=read(); char s[N]; ll x,y;
for(ll i=1;i<=n;i++){
scanf("%s",s+1); c[i].push_back(0),pre[i].push_back(0);
len[i]=strlen(s+1),maxlen=max(maxlen,len[i]);
for(ll j=1;j<=len[i];j++){
c[i].push_back(s[j]-'a'+1);
pre[i].push_back(pre[i][j-1]*P+c[i][j]);
}
}
po[0]=1; for(ll i=1;i<=maxlen;i++) po[i]=po[i-1]*P;
while(ops--){
y=read(),x=read(); maxlen=min(len[x],len[y]);
if(mp1[x].find(y)!=mp1[x].end()){ printf("%lld\n",mp1[x][y]); continue; }
for(ll i=maxlen;i>=0;i--){
if(getsh(x,1,i)==getsh(y,len[y]-i+1,len[y])){
ans=i; break;
}
}
mp1[x][y]=ans;
printf("%d\n",ans);
}
exit(0);
}
T4 显然也是我整的
还没会,先鸽.
这几场考得都不是很让自己满意.
每次考试的策略都很差.
这次考试上来先入手码了码量最长的题,甚至连 \(T1\) 和 \(T3\) 的暴力都没打.
\(T1\) 绝对在自己的能力范围内,自己知道是状压,可能推个规律就出来了.
可是自己偏偏就是看着 \(T2\) 去码较难的.
\(T4\) 连部分分都没拿全,这样的策略怎么可能行..
一定要规划好.
标签:pre,ch,noip,待补,res,ll,72,define,mod 来源: https://www.cnblogs.com/AaMuXiiiiii/p/15390750.html