2017 济南精英班 Day1

不管怎么掰都是n*m-1
#include<cstdio>
using namespace std;
int main()
{
freopen("bpmp.in","r",stdin);
freopen("bpmp.out","w",stdout);
int n,m;
scanf("%d%d",&n,&m);
int ans=(1ll*n*m-)%;
printf("%d",ans);
}

将行状态压缩,枚举哪些行被折成了一条
枚举时,上一次选取的行 与 这一次选取的行 奇偶性不同,这两行才能折到一起
选取列也要求 上一个选的列与这一个选的列奇偶性不同
dp计算这一条上选哪些列
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,ans;
int a[][],c[];
int dp(int s)
{
bool f=false;
memset(c,,sizeof(c));
for(int i=;i<n;i++)
if(s&(<<i))
for(int j=;j<m;j++)
c[j]+=a[i][j];
for(int j=;j<m;j++)
if(c[j]>) { f=true; break; }
if(!f) return -2e9;
int c0=,c1=,x;
for(int i=;i<m;i++)
if(i&) c1=max(c[i]+c0,c1);
else c0=max(c[i]+c1,c0);
return max(c1,c0);
}
void dfs(int now,int last,int state)
{
if(now==n)
{
ans=max(ans,dp(state));
return;
}
if(last==- || ((now-last)&)) dfs(now+,now,state|(<<now));
dfs(now+,last,state);
}
int main()
{
freopen("cfyw.in","r",stdin);
freopen("cfyw.out","w",stdout);
scanf("%d%d",&n,&m);
ans=-2e9;
for(int i=;i<n;i++)
for(int j=;j<m;j++)
scanf("%d",&a[i][j]),ans=max(ans,a[i][j]);
if(ans>) dfs(,-,);
printf("%d",ans);
}

推公式+除法分块
http://www.cnblogs.com/TheRoadToTheGold/p/6696450.html
#include<cstdio>
#include<algorithm>
#define N 10000001
#define mod 998244353
using namespace std;
int p[],phi[N],cnt;
long long sum[N];
bool vis[N];
void pre(int n)
{
phi[]=;
for(int i=;i<=n;i++)
{
if(!vis[i])
{
vis[i]=true;
phi[i]=i-;
p[++cnt]=i;
}
for(int j=;j<=cnt;j++)
{
if(i*p[j]>n) break;
vis[i*p[j]]=true;
if(i%p[j]==)
{
phi[i*p[j]]=phi[i]*p[j];
break;
}
else phi[i*p[j]]=phi[i]*(p[j]-);
}
}
for(int i=;i<=n;i++) sum[i]=sum[i-]+phi[i];
}
int main()
{
freopen("hoip.in","r",stdin);
freopen("hoip.out","w",stdout);
int n,m;
scanf("%d%d",&n,&m);
pre(min(n,m));
long long ans=;
long long j;
for(long long i=;i<=min(n,m);i=j+)
{
j=min(n/(n/i),m/(m/i));
ans=(ans+(sum[j]-sum[i-])*(n/i)%mod*(m/i)%mod)%mod;
}
printf("%I64d",ans);
}
2017 济南精英班 Day1的更多相关文章
- 2017.7.15清北夏令营精英班Day1解题报告
成绩: 预计分数:20+10+40 实际分数:100+10+40. 一百三十多人的比赛全场rand7还水了个鼠标+键盘 unbelievable! 考试题目链接: https://www.luogu. ...
- 洛谷P1080 [NOIP2012提高组D1T2]国王游戏 [2017年5月计划 清北学堂51精英班Day1]
P1080 国王游戏 题目描述 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右 手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 n 位大臣排 ...
- 洛谷P1650 赛马[2017年5月计划 清北学堂51精英班Day1]
P1650 赛马 题目描述 我国历史上有个著名的故事: 那是在2300年以前.齐国的大将军田忌喜欢赛马.他经常和齐王赛马.他和齐王都有三匹马:常规马,上级马,超级马.一共赛三局,每局的胜者可以从负者这 ...
- 洛谷P2258 子矩阵[2017年5月计划 清北学堂51精英班Day1]
题目描述 给出如下定义: 子矩阵:从一个矩阵当中选取某些行和某些列交叉位置所组成的新矩阵(保持行与列的相对顺序)被称为原矩阵的一个子矩阵. 例如,下面左图中选取第2.4行和第2.4.5列交叉位置的元素 ...
- 洛谷P2327 [SCOI2005]扫雷 [2017年5月计划 清北学堂51精英班Day1]
P2327 [SCOI2005]扫雷 题目描述 输入输出格式 输入格式: 第一行为N,第二行有N个数,依次为第二列的格子中的数.(1<= N <= 10000) 输出格式: 一个数,即第一 ...
- 2017 济南综合班 Day 7
a 两个指针L.R R开始指向恰好[R,n]有不超过k个逆序对的地方 随着L的右移,R指针只会右移 逆序对有2部分 1.L左侧与其他位置形成的逆序对 2.R右侧与其他位置形成的逆序对 用树状数组分别 ...
- 2017 济南综合班 Day 6
循环移动 (cyclic.cpp/c/pas) (1s/256M) 问题描述 给出一个字符串S与N个操作.每个操作用三元组(L, R, K)进行描述:操作将字符串第L个到第R个位置构成的子串循环移动K ...
- 2017 济南综合班 Day 5
毕业考试 (exam.cpp/c/pas) (1s/256M) 问题描述 快毕业了,Barry希望能通过期末的N门考试来顺利毕业.如果他的N门考试平均分能够达到V分,则他能够成功毕业.现在已知每门的分 ...
- 2017 济南综合班 Day 4
T1 外星人 二维前缀和 #include<cstdio> #define N 1001 using namespace std; bool v[N][N]; int sum[N][N]; ...
随机推荐
- python knn自我实践
#得到分类数据和测试数据 import pymysql import struct from numpy import * a=['']*20 #存图像 分类数据 b=[[0]*76800]*20#存 ...
- 石家庄铁道大学网站首页UI分析
今天的软件工程王老师讲了UI的设计,以前狭隘的认为只有移动设备上的界面叫UI,百度一下才发现UI其实有这么多含义:UI即User Interface的简称.泛指用户的操作界面,UI设计主要指界面的样式 ...
- static块的本质
在网上看到了下面的一段代码: public class Test { static { _i = 20; } public static int _i = 10; public static void ...
- mysql hql异常
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; nested ex ...
- XML XPath语法总结
刚刚遇到一个多重查询xmlDoc.SelectSingleNode("Root/Element[@Name='大气象'][@Age='30']")根据innerText查询xmlD ...
- 使用git下载编译erlang
git clone https://github.com/erlang/otp cd otp git tag git checkout -b OTP- OTP- ./otp_build all exp ...
- SQL之case when then用法详解
case具有两种格式.简单case函数和case搜索函数. <span style="font-size:14px;">--简单case函数 case sex when ...
- PAT 甲级 1063 Set Similarity
https://pintia.cn/problem-sets/994805342720868352/problems/994805409175420928 Given two sets of inte ...
- vue+postcss报错: variable '--primary-color' is undefined and used without a fallback
之前vue-cli3引入postcss的配置: https://www.cnblogs.com/XHappyness/p/7676680.html 发现这么一个问题,我再全局global.css中定义 ...
- 用Racket语言写了一个万花筒的程序
用Racket语言写了一个万花筒的程序 来源:https://blog.csdn.net/chinazhangyong/article/details/79362394 https://github. ...