记录编号 |
243829 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[IOI 1994] 数塔 |
最终得分 |
100 |
用户昵称 |
AntiLeaf |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.061 s |
提交时间 |
2016-03-30 18:03:04 |
内存使用 |
0.00 MiB |
显示代码纯文本
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- using namespace std;
- namespace mine{
- int c,x,a[110],i,j;
- bool neg;
- inline int getint(){
- x=neg=0;
- do c=getchar();while(c==' '||c=='\n'||c=='\r'||c=='\t');
- if(c=='-'){
- neg=true;
- c=getchar();
- }
- for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+(c^48);
- if(neg)return -x;
- return x;
- }
- inline int fgeti(FILE* fin){
- x=neg=0;
- do c=fgetc(fin);while(c==' '||c=='\n'||c=='\r'||c=='\t');
- if(c=='-'){
- neg=true;
- c=fgetc(fin);
- }
- for(;c>='0'&&c<='9';c=fgetc(fin))x=(x<<1)+(x<<3)+(c^48);
- if(neg)return -x;
- return x;
- }
- inline void putint(int x){
- neg=x<0;
- if(neg)x=-x;
- i=0;
- do{
- a[i++]=x%10+48;
- x/=10;
- }while(x);
- if(neg)putchar('-');
- for(j=i-1;j>=0;j--)putchar(a[j]);
- }
- inline void fputi(FILE* fout,int x){
- neg=x<0;
- if(neg)x=-x;
- i=0;
- do{
- a[i++]=x%10+48;
- x/=10;
- }while(x);
- if(neg)putchar('-');
- for(j=i-1;j>=0;j--)fputc(a[j],fout);
- }
- inline void fputi(int x,FILE* fout){
- neg=x<0;
- if(neg)x=-x;
- i=0;
- do{
- a[i++]=x%10+48;
- x/=10;
- }while(x);
- if(neg)putchar('-');
- for(j=i-1;j>=0;j--)fputc(a[j],fout);
- }
- inline void put(const char* s){
- x=strlen(s);
- for(i=0;i<x;i++)putchar(s[i]);
- }
- inline void fput(FILE* fout,const char* s){
- x=strlen(s);
- for(i=0;i<x;i++)fputc(s[i],fout);
- }
- inline void fput(const char* s,FILE* fout){
- x=strlen(s);
- for(i=0;i<x;i++)fputc(s[i],fout);
- }
- inline void puts(const char* s){
- x=strlen(s);
- for(i=0;i<x;i++)putchar(s[i]);
- putchar('\n');
- }
- inline void fputs(FILE* fout,const char* s){
- x=strlen(s);
- for(i=0;i<x;i++)fputc(s[i],fout);
- fputc('\n',fout);
- }
- inline void fputs(const char* s,FILE* fout){
- x=strlen(s);
- for(i=0;i<x;i++)fputc(s[i],fout);
- fputc('\n',fout);
- }
- }
- int MAIN();
- int haha=MAIN();
- int n,a[90][90],f[90][90];
- bool left[90][90];
- int dfs(int,int);
- int main(){;}
- inline int MAIN(){
- #define COGS
- #ifdef COGS
- freopen("shuta.in","r",stdin);
- freopen("shuta.out","w",stdout);
- #endif
- memset(f,-1,sizeof(f));
- n=mine::getint();
- for(int i=1;i<=n;i++)for(int j=1;j<=i;j++){
- a[i][j]=mine::getint();
- if(i==n)f[i][j]=a[i][j];
- }
- mine::putint(dfs(1,1));
- putchar('\n');
- for(int i=1,j=1;i<=n;i++){
- mine::putint(a[i][j]);
- putchar(' ');
- if(!left[i][j])j++;
- }
- return putchar('\n');
- }
- int dfs(int x,int y){
- if(f[x][y]==-1){
- if(dfs(x+1,y)<dfs(x+1,y+1)){
- left[x][y]=false;
- return f[x][y]=f[x+1][y+1]+a[x][y];
- }
- else{
- left[x][y]=true;
- return f[x][y]=f[x+1][y]+a[x][y];
- }
- }
- return f[x][y];
- }