HDU5691 Sitting in Line【状压DP】】的更多相关文章

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5691 题解: 和tsp用的状压差不多,就是固定了一些访问顺序. dp[i][j]表示前cnt个点中布满状态i且最后一个为j的状态的最大乘积和. 则有dp[i|(1<<k)][k]=max(dp[i|(1<<k)][k],dp[i][j]+a[j]*a[k]). #include<iostream> #include<cstring> #include<c…
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5691 题意:中文,不解释 题解:设dp[i][j]表示当前状态为i,以第j个数为末尾的最忧解,然后dp下去就行了 #include<cstdio> #define F(i,a,b) for(int i=a;i<=b;i++) inline void up(int &x,int y){if(x<y)x=y;} <<][],a[],b[],inf=-(<<)…
在本题中,n<=16n<=16n<=16, 不难想到可以将所选数字的编号进行状态压缩. 定义状态 dp[S][j]dp[S][j]dp[S][j],其中 SSS 代表当前所选出的所有数字编号,jjj 代表当前位置考虑的数字编号. 如果状态合法,可以转移状态 dp[S][j]=max(dp[S][j],dp[Sdp[S][j]=max(dp[S][j], dp[Sdp[S][j]=max(dp[S][j],dp[S^j][k]+val[j]∗val[k])j][k] +val[j]*val…
HDU5691 Sitting in Line 题意: 给出\(n\)个数字,有些数字的位置固定了,现在要求把所有没固定的数字放在一个位置,使得任意相邻两个位置的数字的相乘的和最大 题解: \(n\)只有\(16\),考虑状压\(DP\) \(DP[msk][i]\)表示当前已经选了\(msk\)集合里的数字且最后一个数字下标是\(i\)的最大值 view code //#pragma GCC optimize("O3") //#pragma comment(linker, "…
[BZOJ1688][Usaco2005 Open]Disease Manangement 疾病管理 Description Alas! A set of D (1 <= D <= 15) diseases (numbered 1..D) is running through the farm. Farmer John would like to milk as many of his N (1 <= N <= 1,000) cows as possible. If the mil…
!!!!!!! 第一次学状压DP,其实就是运用位运算来实现一些比较,挺神奇的.. 为什么要发“!!!”因为!x&y和!(x&y)..感受一下.. #include <iostream> #include <cstdio> #include <cstring> #define N 13 #define M 1<<13 #define MOD 1000000000 using namespace std; int n,m,t,ans; int s…
http://codeforces.com/gym/100405 D题 题在pdf里 codeforces.com/gym/100405/attachments/download/2331/20132014-acmicpc-northwestern-european-regional-contest-nwerc-13-en.pdf D - Diagrams & TableauxA Young diagram is an arrangement of boxes in rows and colum…
ZOJ Monthly, August 2014 E题 ZOJ月赛 2014年8月 E题 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5334 Easy 2048 Again Time Limit: 2 Seconds      Memory Limit: 65536 KB Dark_sun knows that on a single-track road (which means once he passed this…
CF453B CF454D Codeforces Round #259 (Div. 2) D Codeforces Round #259 (Div. 1) B D. Little Pony and Harmony Chest time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Princess Twilight went to C…
http://poj.org/problem?id=3254 Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7588   Accepted: 4050 Description Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parc…
G - Simple String Problem Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice FZU 2218 Description Recently, you have found your interest in string theory. Here is an interesting question about strings.…
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5816 Description Hearthstone is an online collectible card game from Blizzard Entertainment. Strategies and luck are the most important factors in this game. When you suffer a desperate situation an…
题目链接 The input contains mutiple testcases. Please process till EOF.For each testcase, the first line contains two integers N (1 ≤ N ≤ 15), the side length of the square map and M (1 ≤ M ≤ 15), the number of tunnels.The map of the city is given in the…
Fighting for Triangles 题目连接: http://codeforces.com/gym/100015/attachments Description Andy and Ralph are playing a two-player game on a triangular board that looks like the following: 1 2 3 4 5 7 8 6 9 10 11 13 14 16 17 12 15 18 At each turn, a playe…
题目链接: 题目 D. Kefa and Dishes time limit per test:2 seconds memory limit per test:256 megabytes 问题描述 When Kefa came to the restaurant and sat at a table, the waiter immediately brought him the menu. There were n dishes. Kefa knows that he needs exactly…
Problem K. Kitchen Robot Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100610 Description Robots are becoming more and more popular. They are used nowadays not only in manufacturing plants, but also at home. One programmer wit…
Clear All of Them I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 122768/62768 K (Java/Others)Total Submission(s): 1455    Accepted Submission(s): 484 Problem Description Acmers have been the Earth Protector against the evil enemy for a lon…
G - 状压dp Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12…
Problem 1608 - Calculation Time Limit: 500MS   Memory Limit: 65536KB    Total Submit: 311  Accepted: 82  Special Judge: No Description Today, Alice got her math homework again! She had n integers, and she needed to divide them into several piles or o…
Resource Archiver Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Others)Total Submission(s): 2382    Accepted Submission(s): 750 Problem Description Great! Your new software is almost finished! The only thing left to…
Wireless Password Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5640    Accepted Submission(s): 1785 Problem Description Liyuan lives in a old apartment. One day, he suddenly found that there…
题目要求若出现x,则不能出现2x,3x 所以我们考虑构造一个矩阵 \(1\ 2\ 4 \ 8--\) \(3\ 6\ 12\ 24--\) \(9\ 18\ 36--\) \(--\) 不难发现,对于一个矩阵,若我选择了一个数x,则在矩阵内该数的相邻格子都不能选,题目就被转化成了玉米田了,可以用状压DP解决 但是直接做是不对的,比如5就没有出现在这个序列中 所以我们可以构造多个矩阵,用乘法原理统计答案即可 #include<bits/stdc++.h> using namespace std;…
题意 n头牛,m个房间,每头牛有自己喜欢的房间,问每头牛都住进自己喜欢的房间有多少种分配方法? Input In the first line of input contains two integers N and M (1 <= N <= 20, 1 <= M <= 20). Then come N lines. The i-th line first contains an integer P (1 <= P <= M) referring to the numb…
Doing Homework Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadline, the…
描述 Bob loves Pizza but is always out of money. One day he reads in the newspapers that his favorite pizza restaurant, Alfredo's Pizza Restaurant, is running a competition: they will donate a big pizza to the first person who will tell them the lowest…
Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadline, the teacher will reduce his score of t…
Farmer John has purchased a lush ≤ M ≤ ; ≤ N ≤ ) square parcels. He wants to grow some yummy corn for the cows on a number of squares. Regrettably, some of the squares are infertile and can't be planted. Canny FJ knows that the cows dislike eating cl…
ACM-ICPC 2018 南京赛区网络预赛E: 题目链接https://www.jisuanke.com/contest/1555?view=challenges Dlsj is competing in a contest with n (0 < n \le 20)n(0<n≤20) problems. And he knows the answer of all of these problems. However, he can submit ii-th problem if and…
由范围可以想到状压dp 两个点(再加上原点)是可以确定一个抛物线的,除非它们解出来a>=0,在本题中是不合法的 这样的话,我们可以预处理出由任意两个点确定的抛物线所经过的所有的点(要特别规定一下自己和自己确定的抛物线只经过自己) 然后设状态s表示目前已经有哪些点被击中了,然后我们钦定这次就要打那个最小的还没击中的点(因为吃枣都要打的嘛),再枚举出另一个还没经过的点,就能得到转移方程 $f[s|line[i][j]]=max\{f[s]+1\}$,其中$line[i][j]$表示i.j两点确定的抛…
http://acm.hdu.edu.cn/showproblem.php?pid=1074 Doing Homework Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12269    Accepted Submission(s): 5911 Problem Description Ignatius has just come bac…