首页 技术 正文
技术 2022年11月21日
0 收藏 566 点赞 4,423 浏览 2172 个字

题意:  

  排队买饭,时间为前一个人和后一个人的异或和,每个人允许其后面B【i】 个人先买到饭,问最少的总用时。

思路:

  用dp【i】【j】【k】 表示1~i-1已经买好饭了,第i个人后面买饭情况为j,最后一个打饭的是i+k。

#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert>using namespace std;
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queuetypedef long long ll;
typedef unsigned long long ull;
//typedef __int128 bll;
typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3;//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n'#define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
#define REP(i , j , k) for(int i = j ; i < k ; ++i)
#define max3(a,b,c) max(max(a,b), c);
#define min3(a,b,c) min(min(a,b), c);
//priority_queue<int ,vector<int>, greater<int> >que;const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const int mod = ;
const double esp = 1e-;
const double PI=acos(-1.0);
const double PHI=0.61803399; //黄金分割点
const double tPHI=0.38196601;template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
}
/*-----------------------showtime----------------------*/
const int maxn = ; int dp[maxn][<<][];
int A[maxn],B[maxn];
int cal(int q,int h){
if(q == ) return ;
return A[q] ^ A[h];
} void solve(){
int n; scanf("%d", &n);
for(int i=; i<=n; i++) scanf("%d%d", &A[i], &B[i]);
memset(dp, inf, sizeof(dp));
dp[][][] = ; for(int i=; i<=n; i++) for(int j=; j<(<<); j++){
for(int k=-; k<=; k++) if(dp[i][j][k+] < inf){
if(j & ) dp[i+][j>>][k+] = min(dp[i+][j>>][k+], dp[i][j][k+]);
else {
int mx = inf;
for(int h = ; h<=; h++) if(! (j & (<<h))){
if(i + h > mx) break;
mx = min(mx, i + h + B[i+h]);
int tmp = dp[i][j][k + ] + cal(i + k, i + h);
dp[i][j | ( << h)][h + ] = min(dp[i][j | ( << h)][h + ], tmp);
}
}
}
}
int ans = inf;
for(int i=; i<=; i++) ans = min(ans, dp[n+][][i]);
cout<<ans<<endl;
}
int main(){
int T; scanf("%d", &T);
while(T--){
solve();
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,905
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,430
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,247
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,058
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,690
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,727