题意:http://acm.hdu.edu.cn/showproblem.php?pid=1565

取不相邻的点是权值最大。

这题可以网络流做,暂时先DP一下,网络流明天学一下~~

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin);
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>// srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
//******************
int abss(int a);
int lowbit(int n);
int Del_bit_1(int n);
int maxx(int a,int b);
int minn(int a,int b);
double fabss(double a);
void swapp(int &a,int &b);
clock_t __STRAT,__END;
double __TOTALTIME;
void _MS(){__STRAT=clock();}
void _ME(){__END=clock();__TOTALTIME=(double)(__END-__STRAT)/CLOCKS_PER_SEC;cout<<"Time: "<<__TOTALTIME<<" s"<<endl;}
//***********************
#define rint register int
#define fo(a,b,c) for(rint a=b;a<=c;++a)
#define fr(a,b,c) for(rint a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
const double E=2.718281828;
const double PI=acos(-1.0);
//const ll INF=(1LL<<60);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e6+; int ok_num[N];
int dp[][];
int a[][]; bool OK(int n,int x)
{
int F[];
F[]=;
for(int i=;i<=n;++i)
F[i]=(x>>(n-i))&;
for(int i=;i<n;++i)
if(F[i]&&F[i+])return ;
return ;
}
int get(int now,int state,int n)
{
int F[];
F[]=;
for(int i=;i<=n;++i)
F[i]=(state>>(n-i))&; int temp=;
for(int i=;i<=n;++i)
if(F[i])temp+=a[now][i];
return temp;
} void solve(int n)
{
int cnt=;
int tot=(<<n)-;
for(int i=;i<=tot;++i)
{
if(OK(n,i))
ok_num[++cnt]=i;
}
// cout<<cnt<<endl;
for(int i=;i<=n;++i)
for(int j=;j<=n;++j)
sc("%d",&a[i][j]);
for(int i=;i<=cnt;++i)
dp[][i]=dp[][i]=;
for(int i=;i<=n;++i)
{
for(int j=;j<=cnt;++j)
{
int temp=get(i,ok_num[j],n);
// dp[1][j]=temp;
for(int k=;k<=cnt;++k)
{
if((ok_num[j]&ok_num[k])==)
dp[][j]=maxx(dp[][j],temp+dp[][k]);
}
}
for(int j=;j<=cnt;++j)
dp[][j]=dp[][j],dp[][j]=;
}
int ans=;
for(int i=;i<=cnt;++i)
ans=maxx(ans,dp[][i]);
pr("%d\n",ans);
} int main()
{
int n;
while(~sc("%d",&n))solve(n);
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}

方格取数--状压DP or 网络流的更多相关文章

  1. HDU 1565 方格取数 状压dp

    题目: 给你一个n*n的格子的棋盘,每个格子里面有一个非负数. 从中取出若干个数,使得任意的两个数所在的格子没有公共边,就是说所取的数所在的2个格子不能相邻,并且取出的数的和最大. Input 包括多 ...

  2. 特殊方格棋盘【状压DP】

    特殊方格棋盘[状压DP] 讲真状压DP这个东西只不过是有那么亿丢丢考验心态罢了(确信) 先从板子题说起,另加一些基础知识 题目描述 在的方格棋盘上放置n 个车,某些格子不能放,求使它们不能互相攻击的方 ...

  3. 【BZOJ5010】【FJOI2017】矩阵填数 [状压DP]

    矩阵填数 Time Limit: 10 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description 给定一个 h*w 的矩阵,矩阵的行 ...

  4. HDU 1565 方格取数(1) 轮廓线dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1565 方格取数(1) Time Limit: 10000/5000 MS (Java/Others) ...

  5. tyvj 1884 [NOIP2000T4]方格取数 || codevs 1043 dp

    P1884 [NOIP2000T4]方格取数 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 [noip2000T4]方格取数 描述 设有N*N的方格图(N& ...

  6. codevs_1043 方格取数(棋盘DP)

    1043 方格取数 2000年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description ...

  7. HRBUST - 1214 NOIP2000提高组 方格取数(多线程dp)

    方格取数 设有N*N的方格图(N<=10),我们将其中的某些方格中填入正整数,而其他的方格中则放人数字0.如下图所示(见样例 ,黄色和蓝色分别为两次走的路线,其中绿色的格子为黄色和蓝色共同走过的 ...

  8. BZOJ 2734 [HNOI2012]集合选数 (状压DP、时间复杂度分析)

    题目链接 https://www.lydsy.com/JudgeOnline/problem.php?id=2734 题解 嗯早就想写的题,昨天因为某些不可告人的原因(大雾)把这题写了,今天再来写题解 ...

  9. 洛谷$P3226\ [HNOI2012]$集合选数 状压$dp$

    正解:$dp$ 解题报告: 传送门$QwQ$ 考虑列一个横坐标为比值为2的等比数列,纵坐标为比值为3的等比数列的表格.发现每个数要选就等价于它的上下左右不能选. 于是就是个状压$dp$板子了$QwQ$ ...

随机推荐

  1. 编译参数(-D)

    程序中可以使用#ifdef来控制输出信息 #include<stdio.h> #define DEBUG int main() { ; ; int sum = a + b; #ifdef ...

  2. 第二章 Python数据导入

    数据导入 数据存储的两个地方: 文件 CSV.Excel.TXT(学习层面) 数据库(公司实战层面) Mysql.Access.SQL Server 导入CSV文件 CSV文件第一行是列名,第二行到最 ...

  3. SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xce in position 0: invalid continuatio

    点击  文档>>设置文件编码>>Unicode>>Unicode(UTF-8)

  4. [Shell] 分隔字符串为数组

    #!/bin/bash tmp="test,girl,boy,love" OLD_IFS="$IFS" IFS="," arr=($a) I ...

  5. RocketMQ使用记录

    ---恢复内容开始--- he following softwares are assumed installed: 64bit OS, Linux/Unix/Mac is recommended; ...

  6. mysql主从复制原理及步骤

    原理: 1master开启bin-log功能,日志文件用于记录数据库的读写增删2需要开启3个线程,master IO线程,slave开启 IO线程 SQL线程,3Slave 通过IO线程连接maste ...

  7. 数据可视化界面UI设计大屏展示

  8. 黑马vue---20、v-if和v-show的使用和特点

    黑马vue---20.v-if和v-show的使用和特点 一.总结 一句话总结: v-if 的特点:每次都会重新删除或创建元素 v-show 的特点: 每次不会重新进行DOM的删除和创建操作,只是切换 ...

  9. webpack publicpath path

    一.publicpath 用绝对路径:如 /assets/ 会在支援路径前 加上 /assets/ devServer  publicpath 如果没有设置的话,取 publicpath 所以 一般要 ...

  10. NoSQL的种类

    https://www.zhihu.com/question/30219620