题目链接:http://codeforces.com/problemset/problem/580/D 题目大意:有n盘菜每个菜都有一个满意度,k个规则,每个规则由x y c组成,表示如果再y之前吃x那么满意度会额外增加c,现在凯迪想吃m盘菜,并且满意度最大,请求出满意度.解题思路:状压DP,设dp[i][j]表示在状态i并且最后一道菜放在位置j时的最大满意度.注意要处理好一道菜时的情况,以及注意二进制表示中1的个数超过m的情况. 代码: #include<bits/stdc++.h> #de…
题意:给定n个菜,每个菜都有一个价值,给定k个规则,每个规则描述吃菜的顺序:i j w,按照先吃i接着吃j,可以多增加w的价值.问如果吃m个菜,最大价值是多大.其中n<=18 思路:一看n这么小,除了暴力之外就得想想状态压缩dp了.因为每种菜正好两种状态(吃过与没吃过),正好可以使用二进制来表示每种状态,那么一共有(1<<n)位种可能,即从状态(000...0)到状态(111...1),所以定义状态dp[s][i],表示状态为s时,并且最后吃第i种菜的时候的最大值.那么转移方程就是 dp…
Kefa and Dishes Problem's Link Mean: 菜单上有n道菜,需要点m道.每道菜的美味值为ai. 有k个规则,每个规则:在吃完第xi道菜后接着吃yi可以多获得vi的美味值. 问:最多可以获得多少美味值? (1≤m≤n≤18,0≤k≤n∗(n−1)) analyse: 经典的状压DP. 由于最多18道菜,可用一个数s(s<=2^18)来唯一标识一种状态. 对于一个状态s,枚举两个位置i和j:i从已选择的菜中选定,j从未选择的菜中选定. 下一个状态ss的就是:吃完i后接着…
题目大概说要吃掉n个食物里m个,吃掉各个食物都会得到一定的满意度,有些食物如果在某些食物之后吃还会增加满意度,问怎么吃满意度最高. dp[S][i]表示已经吃掉的食物集合是S且刚吃的是第i个食物的最大满意度 ..没什么好说的 #include<cstdio> #include<algorithm> using namespace std; ],pairs[][]; <<][]; int getCnt(int s){ ; ; i<; ++i){ ) ++cnt; }…
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output 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 ne…
状态压缩DP裸题,比赛的时候没反应过来,进行了n次枚举起点的solve,导致超时. #include<cstdio> #include<iostream> #include<vector> #include<cstring> using namespace std; int n,m,k; ][],val[]; int a,b,c; <<][]; vector<]; int judge(int x){ ; ){ ) res++; x>&…
题目描述:  A Simple Task time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycle with no repeated vertices or…
Little Pony and Harmony Chest 经典状态压缩dp #include <cstdio> #include <cstring> #include <cstdlib> #include <iostream> #define min(x,y) (x>y?y:x) using namespace std; ],all,n,a[],b[][<<],pre[][<<],s1,s0,f[][<<],ans…
Pieces Assignment My Tags   (Edit)   Source : zhouguyue   Time limit : 1 sec   Memory limit : 64 M Submitted : 444, Accepted : 156 Background 有一个n*m的棋盘(n.m≤80,n*m≤80)要在棋盘上放k(k≤20)个棋子,使得任意两个棋子不相邻(每个棋子最多和周围4个棋子相邻).求合法的方案总数. Input 本题有多组测试数据,每组输入包含三个正整数n…
Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4739   Accepted: 2506 Description Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yumm…