A

暴力

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 1010
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
vector<int>ed[N];
bool w[N][N];
int main()
{
int i,j,n,m;
int flag = ;
cin>>n>>m;
for(i = ; i <= n;i++)
{
int k = ;
w[i][i] = ;
for(j = ; j <= n ; j++)
{
if(!w[i][j])
{
w[i][j] = ;
w[j][i] = ;
ed[i].push_back(j);
k++;
}
if(k==m) break;
}
if(k<m)
{
flag = ;
break;
}
}
if(!flag) {puts("-1");return ;}
printf("%d\n",n*m);
for(i = ; i <= n ;i++)
{
for(j = ; j < ed[i].size(); j++)
printf("%d %d\n",i,ed[i][j]);
}
return ;
}

B 状压

这个需要排下序,不然不能保证压的正确。

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 1010
#define LL long long
//#define INF 1e18+1e12
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
const LL INF = (1ll<<);
LL dp[<<];
struct node
{
int x,k,m;
int a[];
int s;
}p[];
bool cmp(node a,node b)
{
return a.k<b.k;
}
int main()
{
int i,j,n,m;
LL b;
cin>>n>>m>>b;
for(i = ; i < (<<m) ; i++)
dp[i] = INF;
for(i = ; i <= n ;i++)
{
p[i].s = ;
scanf("%d%d%d",&p[i].x,&p[i].k,&p[i].m);
for(j = ; j < p[i].m ; j++)
{
scanf("%d",&p[i].a[j]);
p[i].s|=(<<(p[i].a[j]-));
}
}
sort(p+,p+n+,cmp);
dp[] = ;
LL ans= INF;
for(i = ; i <= n ;i++)
{
for(j = ;j < (<<m) ; j++)
{
if(dp[j]==INF) continue;
dp[j|p[i].s] = min(dp[j|p[i].s],dp[j]+p[i].x);
}
ans = min(ans,dp[(<<m)-]+p[i].k*b);
}
if(ans==INF)
puts("-1");
else
cout<<ans<<endl;
return ;
}

最新文章

  1. Js权限判断处理
  2. STL_lower_bound&amp;upper_bound用法
  3. linux+php+apache web调用python脚本权限问题
  4. C#把数据写到硬盘指定位置
  5. MVC5 + EF6 + Bootstrap3 (11) 排序、搜索、分页
  6. 如何在windows中编写R程序包(转载)
  7. [CentOS 6.5 X64]讓firefox java plugin 啟動
  8. QF——UI之UIViewController
  9. 杭电oj A + B Again
  10. postman的使用大全
  11. php替换字符串函数strtr()和str_repalce()区别
  12. php $_SERVER中的SERVER_NAME 和HTTP_HOST的区别以及REQUEST_URI的讲解
  13. [Linux] - Windows与Linux网络共享文件夹挂载方法
  14. Python2.x与3.x版本区别
  15. var_export
  16. MOSFET中的重要参数
  17. keepalive 原理讲解
  18. js 刷新当前页面会弹出提示框怎样将这个提示框去掉
  19. BZOJ 3091: 城市旅行 lct 期望 splay
  20. 编辑控件的警告提示是:This text field does not specify an inputType or a hint

热门文章

  1. hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
  2. 用Delphi7 调用.NET 2.0的WebService 所要注意的问题(Document格式和UTF8编码)
  3. POJ1077 Eight —— 经典的搜索问题
  4. ping 和 远程桌面 与防火墙的关系
  5. hdu 5615 Jam&#39;s math problem(十字相乘判定)
  6. 内部类 final变量的生命周期
  7. php判断某个变量是否存在
  8. linux学习二(小随笔)
  9. SDOI2016 Round1 题解
  10. absolute属性与IE6/IE7之间的误会