题解:

状压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 ;
}

最新文章

  1. 结对项目:代码复审+PSP
  2. 一次愚蠢的NOIP模拟赛
  3. MotionEvent
  4. C#连接SQLite的字符串
  5. PL/SQL Developer不安装客户端连接远程oracle数据库(转)
  6. Installing Mp4box in centos 6
  7. static class
  8. The 5th tip of DB Query Analyzer
  9. zyUpload界面绝佳、体验超棒的HTML5上传插件
  10. Delphi 10.1说明
  11. twitter 授权过程
  12. List container
  13. ListView控件使用
  14. iOS中 UISearchController 搜索栏 UI技术分享
  15. mysql group by 过滤字段 只能在SELECT 后面出现,不能写其他字段 报错解决 关键字 sql_mode=only_full_group_by
  16. Python之进程 1 - 基本概念
  17. Android NDK 使用自己的共享库(Import Module)
  18. go语言中的并发
  19. zw版【转发&#183;台湾nvp系列Delphi例程】HALCON max_connection
  20. PDB调试模块

热门文章

  1. [BZOJ4244]邮戳拉力赛
  2. Ubuntu 14.04下 Java通用安装方法
  3. Codeforces Round #323 (Div. 2) D. Once Again... 乱搞+LIS
  4. python 元组列表合并
  5. MongoDB(课时11 嵌套集合)
  6. 【转】Qt在pro中设置运行时库MT、MTd、MD、MDd,只适合VS版本的Qt
  7. 【转】C/C++ 函数指针与类函数指针
  8. 【python】print &#183; sys.stdout &#183; sys.stderr
  9. 家里各台机器的php性能测试
  10. Freemarker 简介