Contest 3
A:非常裸的dp。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
#define P 1000000007
#define N 32
int a,b,c,d,f[N][N][N][N][];
void inc(int &x,int y){x+=y;if (x>=P) x-=P;}
int main()
{
freopen("count.in","r",stdin);
freopen("count.out","w",stdout);
a=read(),b=read(),c=read(),d=read();
f[][][][][]=f[][][][][]=f[][][][][]=f[][][][][]=;
for (int i=;i<a+b+c+d;i++)
for (int x=;x<=a;x++)
for (int y=;y<=b;y++)
for (int z=;z<=c;z++)
{
int t=i-x-y-z;
if (t>d) continue;
for (int p=;p<;p++)
for (int q=;q<;q++)
if (p!=q)
{
if (q==&&x<a) inc(f[x+][y][z][t][q],f[x][y][z][t][p]);
if (q==&&y<b) inc(f[x][y+][z][t][q],f[x][y][z][t][p]);
if (q==&&z<c) inc(f[x][y][z+][t][q],f[x][y][z][t][p]);
if (q==&&t<d) inc(f[x][y][z][t+][q],f[x][y][z][t][p]);
}
}
cout<<((f[a][b][c][d][]+f[a][b][c][d][])%P+(f[a][b][c][d][]+f[a][b][c][d][])%P)%P;
return ;
}
B:非常裸的组合。我又学傻了第一眼居然容斥还好拍了。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
#define N 200010
#define P 1000000007
int n,m,k,ans=,fac[N],inv[N];
int C(int n,int m){return 1ll*fac[n]*inv[m]%P*inv[n-m]%P;}
int main()
{
freopen("array.in","r",stdin);
freopen("array.out","w",stdout);
n=read(),m=read(),k=read();
fac[]=;for (int i=;i<=n+m;i++) fac[i]=1ll*fac[i-]*i%P;
inv[]=inv[]=;for (int i=;i<=n+m;i++) inv[i]=P-1ll*(P/i)*inv[P%i]%P;
for (int i=;i<=n+m;i++) inv[i]=1ll*inv[i]*inv[i-]%P;
if (m-k&) {cout<<;return ;}
cout<<1ll*C(n,k)*C((m-k>>)+n-,n-)%P;
return ;
}
C:非常裸的meet in the middle。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
#define N 300010
#define ll long long
int n,b[];
ll a[][N],l,r,ans,m;
void dfs(int k,int n,int p,ll s)
{
if (k>n) a[p][++a[p][]]=s;
else
{
dfs(k+,n,p,s);
dfs(k+,n,p,s+b[k]);
}
}
ll calc(ll k)
{
ll s=;int x=a[][];
for (int i=;i<=a[][];i++)
{
while (x&&a[][x]+a[][i]>k) x--;
s+=x;
}
return s;
}
int main()
{
freopen("subset.in","r",stdin);
freopen("subset.out","w",stdout);
n=read();cin>>m;
for (int i=;i<=n;i++) r+=(b[i]=read());
dfs(,n>>,,);
dfs((n>>)+,n,,);
sort(a[]+,a[]+a[][]+);
sort(a[]+,a[]+a[][]+);
while (l<=r)
{
ll mid=l+r>>;
if (calc(mid)>=m) ans=mid,r=mid-;
else l=mid+;
}
cout<<ans;
return ;
}
result:300 rank1
Contest 3的更多相关文章
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
- hdu 4946 2014 Multi-University Training Contest 8
Area of Mushroom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- 2016 Multi-University Training Contest 2 D. Differencia
Differencia Time Limit: 10000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- 2016 Multi-University Training Contest 1 G. Rigid Frameworks
Rigid Frameworks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- hdu-5988 Coding Contest(费用流)
题目链接: Coding Contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- ZOJ 3703 Happy Programming Contest
偏方记录背包里的物品.....每个背包的价值+0.01 Happy Programming Contest Time Limit: 2 Seconds Memory Limit: 65536 ...
- 2012 Multi-University Training Contest 9 / hdu4389
2012 Multi-University Training Contest 9 / hdu4389 打巨表,实为数位dp 还不太懂 先这样放着.. 对于打表,当然我们不能直接打,这里有技巧.我们可以 ...
- 2014 Multi-University Training Contest 9#11
2014 Multi-University Training Contest 9#11 Killing MonstersTime Limit: 2000/1000 MS (Java/Others) ...
- 2014 Multi-University Training Contest 9#6
2014 Multi-University Training Contest 9#6 Fast Matrix CalculationTime Limit: 2000/1000 MS (Java/Oth ...
- 校际联合Contest
每次开一个坑都像是重新被碾压的预感 最近的新闻,以前很喜欢乔任梁的<复活>...然后他就死了...感觉我再多愁善感一点的话...就要悲伤逆流成河了吧... Contest 09/24(乐滋 ...
随机推荐
- [BZOJ2961]共点圆-[凸包+cdq分治]
Description 传送门 Solution 考虑对于每一个点: 设圆的坐标为(x,y),点的坐标为(x0,y0).依题意得,当一个点在圆里,需要满足(x-x0)2+(y-y0)2<=x2+ ...
- 人脸识别引擎SeetaFaceEngine中Identification模块使用的测试代码
人脸识别引擎SeetaFaceEngine中Identification模块用于比较两幅人脸图像的相似度,以下是测试代码: int test_recognize() { const std::stri ...
- Linux安装gitlab
一.GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务.安装方法是参考GitLab在GitHub上的Wiki页面. 二.我相信使用过git的开 ...
- Yii2.0 技巧总结
View部分 1. 使用ActiveField中的hint生成提示文字 <?= $form->field($model, 'freightAddedFee')->textInput( ...
- Linux 的字符串截取
假设有变量 var=http://www.aaa.com/123.htm 1. # 号截取,删除左边字符,保留右边字符. echo ${var#*//} 其中 var 是变量名,# 号是运算符,*// ...
- 180727-时序数据库InfluxDB之备份和恢复策略
influxdb 备份与恢复 参考: influxdb backup and restore 环境: influxdb v1.6.0 使用influx自动的控制台进行 I. 备份 备份命令 influ ...
- CentOS 7.2二进制安装mysql-5.7.19
官方文档地址:https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html 开始安装 1.下载mysql二进制包 # cd /usr ...
- 第k小分数(二分值)
//时间限制:10000ms //单点时限:1000ms //内存限制:256MB //描述 //给定N个不同的质数P1, P2, … PN.用它们作为分目可以组成(P1-1) + (P2-1) + ...
- Spark之spark shell
前言:要学习spark程序开发,建议先学习spark-shell交互式学习,加深对spark程序开发的理解.spark-shell提供了一种学习API的简单方式,以及一个能够进行交互式分析数据的强大工 ...
- 【shell 每日一练7】一键安装mysql5.7,以及密码及策略修改
一.一键安装Mysql脚本 [root@uat01 ~]# cat InstallMysql01.sh #!/bin/bash #-- #旅行者-Travel #.安装wget yum -y inst ...