洛谷CON1041 NOIP模拟赛一试

时间:2023-03-09 20:04:31
洛谷CON1041 NOIP模拟赛一试

A

T2-power of 2

题目描述

洛谷CON1041 NOIP模拟赛一试是一个十分特殊的式子。

例如:

n=0时 洛谷CON1041 NOIP模拟赛一试=2

然而,洛谷CON1041 NOIP模拟赛一试太大了

所以,我们让洛谷CON1041 NOIP模拟赛一试对10007 取模

输入输出格式

输入格式:

n

输出格式:

洛谷CON1041 NOIP模拟赛一试 % 10007

输入输出样例

输入样例#1:
2
输出样例#1:
16

说明

n<=1000000


2^(2^n)

快速幂的方式log幂....就是n次平方

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#define debug(x) cout<<#x<<'='<<x<<' '
using namespace std;
typedef long long ll;
const int MOD=;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
int n;
int ans=;
int main(){
n=read();
if(n==){cout<<;return ;}
while(n--){
ans=(ans*ans)%MOD;
}
printf("%d",ans%MOD);
}


C

T3-cube

题目描述

有一个立方体,分成了洛谷CON1041 NOIP模拟赛一试个完全相等的小格

有的小格出现了糖果,如果一个格子出现多次糖果,则以最后得糖果数为准,你到了这个小格就可以拿,你在(1,1,1),你要走到(n,n,n),且只能走最短路径

问:你最多能拿到多少糖果

输入输出格式

输入格式:

n 以下若干行(EOF结束),每行4个数,前三个数是坐标,最后一个数是糖果个数

输出格式:

你最多拿到的糖果数

输入输出样例

输入样例#1:
2
1 1 1 3
1 1 2 4
2 1 2 5
输出样例#1:
12
输入样例#2:
5
输出样例#2:
0

说明

n<=100

糖果数<=100


水DP,立体了而已

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#define debug(x) cout<<#x<<'='<<x<<' '
using namespace std;
const int N=;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
int n,x,y,z,w[N][N][N];
int f[N][N][N];
int main(){
n=read();
while(scanf("%d%d%d",&x,&y,&z)!=EOF) w[x][y][z]=read();
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
for(int k=;k<=n;k++)
f[i][j][k]=max(f[i-][j][k],max(f[i][j-][k],f[i][j][k-]))+w[i][j][k];
printf("%d",f[n][n][n]);
}


D

T4-cube2

题目描述

还是那个立方体

还是那些糖

只是你需要走两次

输入输出格式

输入格式:

见T3

输出格式:

同上

输入输出样例

输入样例#1:
2
1 1 2 3
1 2 2 3
1 2 1 3
输出样例#1:
9

说明

n<=10


立体版传纸条

(1,1,1)和(n,n,n)也不知道怎么搞的

#include <iostream>
#include <cstdio>
//#include <algorithm>
#include <cstring>
#include <cmath>
#define debug(x) cout<<#x<<'='<<x<<' '
using namespace std;
typedef long long ll;
const int N=;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
int n,x,y,z,w[N][N][N];
int f[N][N][N][N][N*];
inline int max(int a,int b){
return a>b?a:b;
}
void dp(){
for(int s=;s<=n*;s++)
for(int i=;i<s&&i<=n;i++)
for(int j=;(i+j)<s&&j<=n;j++)
for(int k=;k<s&&k<=n;k++)
for(int l=;(l+k)<s&&l<=n;l++){
int z1=s-(i+j),z2=s-(k+l);
if(z1>n||z2>n) continue;
if(i==k&&j==l&&s!=*n) continue;
int mx1=max(f[i-][j][k-][l][s-],f[i-][j][k][l-][s-]);
mx1=max(f[i-][j][k][l][s-],mx1);
int mx2=max(f[i][j-][k-][l][s-],f[i][j-][k][l-][s-]);
mx2=max(f[i][j-][k][l][s-],mx2);
int mx3=max(f[i][j][k-][l][s-],f[i][j][k][l-][s-]);
mx3=max(f[i][j][k][l][s-],mx3);
f[i][j][k][l][s]=max(mx1,max(mx2,mx3))+w[i][j][z1]+w[k][l][z2]; //printf("%d %d %d %d %d %d\n",i,j,k,l,s,f[i][j][k][l][s]);
}
}
int main(){
n=read();
while(scanf("%d%d%d",&x,&y,&z)!=EOF) w[x][y][z]=read();
dp();
printf("%d",f[n][n][n][n][*n]-w[n][n][n]+w[][][]);
}


B