不充钱,你怎么AC?

  题目:http://codevs.cn/problem/1166/

  有许久没有刷题了,忙着过中秋去了嘿嘿

  首先它的每一行是独立的,我们可以直接把它拆分成 n 互不相关的子问题做

  那么就变成了区间 DP 问题,f[i][j] 表示在区间 [i,j] 内的最大分数,首先枚举区间长度 k,然后再枚举左端点 i

    

  n 表示的是一行数的个数

  注意 k 要到-1,是因为 f[i][i] 时还有一个 a[i] 没有取走,目标状态是 max ( f[i][i-1] ) ,(i=1~n)

 #include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#define N 90
using namespace std; long long a[N],f[N][N],m,ans,t,n;
int main()
{
long long i,k;
cin>>t>>n;
while (t>)
{
t--;
for (i=;i<=n;i++) cin>>a[i];
for (k=n-;k>=-;k--)
{
for (i=;i<=n-k;i++)
{
f[i][i+k]=max(f[i-][i+k]+a[i-]*(<<(n-k-)),f[i][i+k+]+a[i+k+]*(<<(n-k-)));
}
}
m=;
for (i=;i<=n;i++) m=max(m,f[i][i-]);
ans+=m;
}
cout<<ans<<endl;
return ;
}

  这段代码交上去只有60分,是为什么呢?

  查了很久的问题,结果返回一看题目数据范围,要写高精度……当年应该觉得这道题太简单了,于是就放个高精度卡掉选手40分

  那么就写一个高精度的加法和比较大小即可,直接贴别人的代码嘿嘿

 #include<cstdio>
#include<cstring>
#include<iostream>
#define maxn 100
#define base 10000
using namespace std; int n,m,cnt=,lp[],rp[];
int map[][];
struct Bign
{
int c[maxn],len;
Bign ()
{
memset(c,,sizeof(c)),len=;
}
void Zero()
{
while(len>&&c[len]==)len--;
}
void Write(char *s)
{
int l=strlen(s);
int k=;
for(int i=l-;i>=;i--)
{
c[len]+=k*(s[i]-'');
k*=;
if(k==base)
{
k=;len++;
}
}
}
void Read()
{
char s[maxn];
scanf("%s",s);
Write(s);
}
void Print()
{
printf("%d",c[len]);
for(int i=len-;i>=;i--) printf("%04d",c[i]);
printf("\n");
}
Bign operator = (const int &a)
{
memset(c,,sizeof(c));
len=;
char s[maxn];
sprintf(s,"%d",a);
Write(s);
Zero();
return *this;
}
Bign operator +(const Bign &a)
{
Bign r;
r.len=max(len,a.len)+;
for(int i=;i<=r.len;i++)
{
r.c[i]+=c[i]+a.c[i];
r.c[i+]+=r.c[i]/base;
r.c[i]%=base;
}
r.Zero();
return r;
}
Bign operator +(const int &a)
{
Bign b;
b=a;
return *this+b;
}
Bign operator *(const Bign &a)
{
Bign r;
r.len=len+a.len+;
for(int i=;i<=len;i++)
{
for(int j=;j<=a.len;j++)
{
r.c[i+j-]+=c[i]*a.c[j];
}
}
for(int i=;i<=r.len;i++)
{
r.c[i+]+=r.c[i]/base;
r.c[i]%=base;
}
r.Zero();
return r;
}
Bign operator *(const int &a)
{
Bign b;
b=a;
return *this*b;
}
bool operator < (const Bign &b)const
{
if(len!=b.len) return len<b.len;
else
{
for(int i=len;i>=;i--)
{
if(c[i]!=b.c[i]) return c[i]<b.c[i];
}
}
return ;
}
bool operator >(const Bign &b)const
{
return b<*this;
}
bool operator <=(const Bign &b)const
{
return !(b>*this);
}
bool operator >=(const Bign &b)const
{
return !(b<*this);
}
bool operator == (int a)
{
return len== && c[len]==a;
}
};
Bign f[][];
Bign Max(Bign a,Bign b)
{
if(a>=b) return a;
if(a<b) return b;
}
int main()
{
Bign ans;
ans=;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
scanf("%d",&map[i][j]);
}
}
for (int i=;i<=n;i++)
{
for(int u=;u<=m;u++)
for(int v=;v<=m;v++) f[v][u]=;
for (int j=;j<=m;j++)
{
f[j][j]=map[i][j]*;
}
for(int len=;len<=m-;len++)
{
for(int l=;l<=m&&l+len<=m;l++)
{
Bign k;
k=max(f[l+][l+len]+map[i][l],f[l][l+len-]+map[i][l+len]);
f[l][l+len]=k*;
}
}
ans=ans+f[][m];
}
ans.Print() ;
return ;
}

[ CodeVS冲杯之路 ] P1166的更多相关文章

  1. [ CodeVS冲杯之路 ] P1368

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/1368/ 嗯……泡泡堂,很劲啊,其实就是个盗版的田忌赛马 http://www.cnblogs.com/hyfer/p/ ...

  2. [ CodeVS冲杯之路 ] P1092

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/1092/ 嗯,这道题有一定难度啊,需要先用扩展欧几里得算法求出逆元,然后按照大小构一颗带边权为小时数的树 树链剖分后在树 ...

  3. [ CodeVS冲杯之路 ] P3955

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/3955/ 最长上升子序列的加强版,n 有1000000,n 方的 DP 肯定会 TLE,那么用二分栈维护 二分栈我讲不好 ...

  4. [ CodeVS冲杯之路 ] P1165

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/1165/ 题目很简单,代码最好写朴实一点,不要想着哪些情况可以合并在一起啊等等 老老实实一个个判断,不然很容易出错 细节 ...

  5. [ CodeVS冲杯之路 ] P1053

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/1053/ 直接扫一遍串,把字母对应的 ascii 码直接做数组下标,交给数组统计 最后查询一遍数组的 'a'-'z' , ...

  6. [ CodeVS冲杯之路 ] P1171

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/1171/ 代码调了很久才调好啊,一开始题目都看错了(要是真的NOIP肯定没戏了QuQ) 后面发现CodeVS上的数据输入 ...

  7. [ CodeVS冲杯之路 ] P1197

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/1197/ 密钥的字母可以全转换为小写字母,然后一一映射,a→0,b→1,c→2,依此类推 对于密文只需将每一位减去对应密 ...

  8. [ CodeVS冲杯之路 ] P2492

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/2492/ 在此先orz小胖子,教我怎么路径压缩链表,那么这样就可以在任意节点跳进链表啦(手动@LCF) 对于查询操作,直 ...

  9. [ CodeVS冲杯之路 ] P2456

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/2456/ 用贪心的思想,木材当然要尽量分成多的木板,而大的木材能够分成大木板,但是小的木材不一定能够分成大的木板,所以木 ...

随机推荐

  1. thinkphp5控制器向+vue的data里传值

    传一维数组传值 $array=['id'=>40,"cat_name"=>"明星产品"]; $MenuCats_info=json_encode($ ...

  2. <Docker学习>5. docker数据管理

    当我们创建了一个tomcat容器,如何简单部署一个web应用?如何将war包放入到容器中?也就是说怎么样把文件从宿主机中 "放入" 到容器中? docker cp命令可以将宿主机本 ...

  3. C细节错误

    2018.11.20 (1)有关优先级的细节 while (c = getchar() && c == '\n') { printf("c = %d\n", c); ...

  4. Codeforces Round #481 (Div. 3) 全题解

    A题,题目链接:http://codeforces.com/contest/978/problem/A 解题心得:题意就是让你将这个数列去重,重复的数只保留最右边的那个,最后按顺序打印数列.set+m ...

  5. 2 实现第一个Django网站 博客

    -1.理解上下文 render()渲染 request  url传来的reuqest x.html 制定返回的模板名称 context 上下文    数据库中 替换数据 0.大框架 1.创建模板 (1 ...

  6. HDU 5293 Tree chain problem 树形DP

    题意: 给出一棵\(n\)个节点的树和\(m\)条链,每条链有一个权值. 从中选出若干条链,两两不相交,并且使得权值之和最大. 分析: 题解 #include <cstdio> #incl ...

  7. 使用系统的某些block api(如UIView的block版本写动画时),是否也考虑循环引用问题?

    系统的某些block api中,UIView的block版本写动画时不需要考虑,但也有一些api 需要考虑 以下这些使用方式不会引起循环引用的问题 [UIView animateWithDuratio ...

  8. leetcode 【 Intersection of Two Linked Lists 】python 实现

    题目: Write a program to find the node at which the intersection of two singly linked lists begins. Fo ...

  9. python 之发送邮件服务[原著] 海瑞博客

    Python 发送邮件 使用默认的django的发送邮件,只适用于单邮箱. 作者:海瑞博客 http://www.hairuinet.com/ setting中配置 # send e-mail EMA ...

  10. Gluon

    推荐一门mxnet的学习框架gluon 首先是学习网址链接gluon 基本环节分成两部分 从0开始(介绍不使用框架,而只使用mxnet来完成神经网络的搭建) gluon实现(介绍使用框架快速搭建神经网 ...