百度之星Astar2016 Round2A
All X
等比数列求和一下 A/B MOD C = A MOD (B*C) / B 或者分治一下
Sitting in Line
状压+拓扑dp
dp(i, j)表示当前二进制状态为j,当前状态的最后一个数字是a[i],然后按照拓扑序dp进行更新,并用一个bool数组记录是否在队列中。
网上还有其他优美的姿势,按某种枚举方式可以达到拓扑序。
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int a[], p[], n; //输入的第i个数是否固定
int vis[], now[];//输出的第i个数是否确定
ll dp[][<<];
bool isin[][<<];
struct P{
int x, y;
P(){}
P(int x, int y):x(x), y(y){}
}; int main(){
int T, ca = ;
cin>>T;
while(T--){
memset(vis, , sizeof(vis));
cin>>n;
for(int i = ; i < n; i++){
cin>>a[i]>>p[i];
if(p[i] != -){
vis[ p[i] ] = true;
now[ p[i] ] = i;
}
} memset(dp, 0x80, sizeof(dp));
memset(isin, , sizeof(isin));
queue<P> Q;
if(vis[]){
dp[ now[] ][ <<now[] ] = ;
isin[ now[] ][ <<now[] ] = true;
Q.push( P(now[], <<now[]) );
}
else{
for(int i = ; i < n; i++)
if(p[i] == -){
dp[i][<<i] = ;
isin[i][<<i] = true;
Q.push( P(i, <<i) );
}
} for(int i = ; i < n; i++){//pos
int size = Q.size();
for(int j = ; j < size; j++){
P pp = Q.front();
Q.pop();
if(vis[i]){
dp[ now[i] ][ pp.y|(<<now[i]) ] = max(dp[ now[i] ][ pp.y|(<<now[i]) ] , dp[pp.x][pp.y]+a[pp.x]*a[ now[i] ]);
if(isin[ now[i] ][ pp.y|(<<now[i]) ] == false)
Q.push( P(now[i], pp.y|(<<now[i])) ), isin[ now[i] ][ pp.y|(<<now[i]) ] = true;
}
else{
for(int k = ; k < n; k++){
if( (pp.y&(<<k)) == &&p[k] == -){
dp[k][pp.y|(<<k)] = max(dp[k][pp.y|(<<k)] , dp[pp.x][pp.y]+a[pp.x]*a[k]);
if(isin[ k ][ pp.y|(<<k) ] == false)
Q.push( P(k, pp.y|(<<k)) ), isin[ k ][ pp.y|(<<k) ] = true;
}
}
}
}
} ll ans = -1e17;
for(int i = ; i < n; i++)
ans = max(ans, dp[i][ (<<n)- ]);
printf("Case #%d:\n", ca++);
cout<<ans<<endl;
}
return ;
}
BD String
从某个点断开后,后面的部分折到前面来,刚好和前面部分的后半段拼成一个整体。
#include <bits/stdc++.h>
typedef long long ll;
using namespace std; ll getsum(ll x){
if(x <= )
return x; ll fir = ;
while( fir* <= x)
fir <<= ; return 1LL+x-fir + getsum( fir-(x-fir)- );
}
int main(){
int t, ca = ;
ll l, r;
cin>>t;
while(t--){
cin>>l>>r;
ll ans = getsum(r)-getsum(l-);
cout<<ans<<endl;
}
return ;
}
Gym Class
SB拓扑排序即可。
百度之星Astar2016 Round2A的更多相关文章
- 2016"百度之星" - 初赛(Astar Round2A)HDU 5695 拓扑排序+优先队列
Gym Class Time Limit: 6000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- 2016百度之星 初赛2A ABEF
只做了1001 1002 1005 1006.剩下2题可能以后补? http://acm.hdu.edu.cn/search.php?field=problem&key=2016%22%B0% ...
- HDU 5690:2016"百度之星" - 初赛 All X
原文链接:https://www.dreamwings.cn/hdu5690/2657.html All X Time Limit: 2000/1000 MS (Java/Others) Mem ...
- 2016百度之星 资格赛ABCDE
看题:http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=690 交题:http://acm.hdu.edu.cn/search.php ...
- HDU 5688:2016"百度之星" - 资格赛 Problem D
原文链接:https://www.dreamwings.cn/hdu5688/2650.html Problem D Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 5686:2016"百度之星" - 资格赛 Problem B
原文链接:https://www.dreamwings.cn/hdu5686/2645.html Problem B Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 5685:2016"百度之星" - 资格赛 Problem A
原文链接:https://www.dreamwings.cn/hdu5685/2637.html Problem A Time Limit: 2000/1000 MS (Java/Others) ...
- 百度之星A
Scenic Popularity Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- 【百度之星2014~初赛(第二轮)解题报告】Chess
声明 笔者近期意外的发现 笔者的个人站点http://tiankonguse.com/ 的非常多文章被其他站点转载.可是转载时未声明文章来源或參考自 http://tiankonguse.com/ 站 ...
随机推荐
- Android内存溢出解决方案(OOM)
众所周知,每个Android应用程序在运行时都有一定的内存限制,限制大小一般为16MB或24MB(视平台而定).因此在开发应用时需要特别关注自身的内存使用量,而一般最耗内存量的资源,一般是图片.音频文 ...
- PHP实现单例模式
<?php /** * [单例模式] * 总结:防止外部new对象:防止子类继承:防止克隆. */ header("Content-type: text/html; charset=u ...
- set_include_path — 设置 include_path 配置选项为当前脚本设置 include_path 运行时的配置选项。
说明 string set_include_path ( string $new_include_path ) 为当前脚本设置 include_path 运行时的配置选项. 参数 new_includ ...
- Asp.net mvc5 解析route源码实现自己的route系统
url route 路由系统的责任是找到匹配的路由,创建路由数据,并将请求分配给一个处理程序. 选择动作是 MVC 的处理程序的实现细节.它使用路由数据和从传入请求其他信息来选择要执行的操作 实例 源 ...
- 2015-11-04 报表 (asp.net 部分)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Scrap_p.aspx.cs& ...
- andriod 新建Activity_ Form
在一个Android工程,如何新建一个Activity? 一:新建一个类(*.class),继承自android.app.Activity类. 二:在res/layout目录下新建一个布局xml文件, ...
- 2016年6月25日 星期六 --出埃及记 Exodus 14:22
2016年6月25日 星期六 --出埃及记 Exodus 14:22 and the Israelites went through the sea on dry ground, with a wal ...
- shell脚本之lnmp的搭建
!/bin/bash #this script is source packages installed lnmp .xmal yum -y install wget #"========= ...
- 编译android源码官方教程(1)硬件、系统要求
https://source.android.com/source/requirements.html Requirements IN THIS DOCUMENT Hardware requireme ...
- 你不知道的This和Class
Oh no....我的This又丢失了??? 为什么我用Class'实例化'出来的对象会相互影响??? ####这些问题都是因为JS的运行机制造成的.在JS中所有的一切都是对象,而this是对象的一个 ...