bzoj1087
2024-09-03 00:55:11
题解:
状压dp
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=;
int n,m,cnt[N],c1[N],c2[N][N];
ll ans,f[][N][N];
void pre()
{
int s;
for (int i=;i<<<n;i++)
if ((i&(i>>))==)
{
s=;
for (int x=i;x;x>>=)s+=(x&);
cnt[i]=s;c1[i]=;
}
for (int i=;i<<<n;i++)
if (c1[i])
for (int j=;j<<<n;j++)
if (c1[j])
if (((i&j)==)&&((i&(j>>))==)&&((j&(i>>))==))c2[i][j]=;
}
int main()
{
scanf("%d%d",&n,&m);
pre();
for (int i=;i<<<n;i++)
if (c1[i])f[][cnt[i]][i]=;
for (int j=;j<n;j++)
for (int k=;k<<<n;k++)
if (c1[k])
for (int i=;i<<<n;i++)
if (c1[i])
if (c2[k][i])
for (int p=cnt[k];p+cnt[i]<=m;p++)f[j+][p+cnt[i]][i]+=f[j][p][k];
ll ans=;
for (int i=;i<<<n;i++)ans+=f[n][m][i];
printf("%lld",ans);
return ;
}
最新文章
- 结对项目:代码复审+PSP
- 一次愚蠢的NOIP模拟赛
- MotionEvent
- C#连接SQLite的字符串
- PL/SQL Developer不安装客户端连接远程oracle数据库(转)
- Installing Mp4box in centos 6
- static class
- The 5th tip of DB Query Analyzer
- zyUpload界面绝佳、体验超棒的HTML5上传插件
- Delphi 10.1说明
- twitter 授权过程
- List container
- ListView控件使用
- iOS中 UISearchController 搜索栏 UI技术分享
- mysql group by 过滤字段 只能在SELECT 后面出现,不能写其他字段 报错解决 关键字 sql_mode=only_full_group_by
- Python之进程 1 - 基本概念
- Android NDK 使用自己的共享库(Import Module)
- go语言中的并发
- zw版【转发&#183;台湾nvp系列Delphi例程】HALCON max_connection
- PDB调试模块
热门文章
- [BZOJ4244]邮戳拉力赛
- Ubuntu 14.04下 Java通用安装方法
- Codeforces Round #323 (Div. 2) D. Once Again... 乱搞+LIS
- python 元组列表合并
- MongoDB(课时11 嵌套集合)
- 【转】Qt在pro中设置运行时库MT、MTd、MD、MDd,只适合VS版本的Qt
- 【转】C/C++ 函数指针与类函数指针
- 【python】print &#183; sys.stdout &#183; sys.stderr
- 家里各台机器的php性能测试
- Freemarker 简介