1. 程式人生 > 其它 >noip模擬71(待補)

noip模擬71(待補)

「T1 出了個大陰間題·T2 最簡單辣快來做·T3 是我的你不要搶·T4 顯然也是我整的」

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\) 連部分分都沒拿全,這樣的策略怎麼可能行..

一定要規劃好.