Headmaster's Headache UVA10817

不等不说这道题其实是一个背包类似物

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>   
#include <map>
#include <string>  
#include <climits> 
#include <set>
#include <string> 
#include <sstream>
#include <utility>
#include <ctime>
 
using std::priority_queue;
using std::vector;
using std::swap;
using std::stack;
using std::sort;
using std::max;
using std::min;
using std::pair;
using std::map;
using std::string;
using std::cin;
using std::cout;
using std::set;
using std::queue;
using std::string;
using std::istringstream;
using std::make_pair;
using std::greater;
using std::endl;

const int INFI(INT_MAX-100000);

int table[1 << 8][1 << 8];
int cost[110], state[110];

int main()
{
	int s;
	while(scanf("%d", &s), s)
	{
		for(int i = 0; i < (1 << s); ++i)
			for(int j = 0; j < (1 << s); ++j)
				table[i][j] = INFI;
		int m, n;
		scanf("%d%d", &m, &n);
		int tw, fc = 0;
		int st1 = 0, st2 = 0;
		for(int i = 1; i <= m; ++i)
		{
			scanf("%d", &tw);
			fc += tw;
			char tc = getchar();
			while(tc != '\n')
			{
				if(!isdigit(tc))
				{
					tc = getchar();
					continue;
				}
				int temp = 0;
				while(isdigit(tc))
				{
					temp *= 10;
					temp += tc-'0';
					tc = getchar();
				}
				--temp;
				if(st1&(1 << temp))
					st2 |= 1 << temp;
				else
					st1 |= 1 << temp;
			}
		}	
		table[st1][st2] = fc;
		for(int i = 1; i <= n; ++i)
		{
			scanf("%d", cost+i);
			state[i] = 0;
			char tc = getchar();
			while(tc != '\n')
			{
				if(!isdigit(tc))
				{
					tc = getchar();
					continue;
				}
				int temp = 0;
				while(isdigit(tc))
				{
					temp *= 10;
					temp += tc-'0';
					tc = getchar();
				}
				--temp;
				state[i] |= 1 << temp;
			}
		}
		for(int i = 1; i <= n; ++i)
		{
			int ts1, ts2;
			for(int j = (1 << s)-1; j >= 0; --j)
				for(int k = (1 << s)-1; k >= 0; --k)
					if(table[j][k] < INFI)
					{
						ts1 = j|state[i];
						ts2 = (j&state[i])|k;
						table[ts1][ts2] = min(table[ts1][ts2], table[j][k]+cost[i]);
					}
		}
		printf("%d\n", table[(1 << s)-1][(1 << s)-1]);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
创建校长信息表`HeadMaster`的SQL语句如下: ``` CREATE TABLE HeadMaster ( HeadID CHAR(4) NOT NULL, Head_Name CHAR(10) NOT NULL, S_ID CHAR(4) NOT NULL, App_Date DATETIME, CONSTRAINT PK_HeadMaster PRIMARY KEY (HeadID), CONSTRAINT FK_HeadMaster_S_ID FOREIGN KEY (S_ID) REFERENCES School(S_ID) ); ``` 其中,`HeadID`、`Head_Name`、`S_ID`、`App_Date`分别是校长信息表`HeadMaster`的列名,对应的中文列名分别是校长编号、姓名、学校编号、任职日期。数据类型和长度分别如题所述。`App_Date`列为校长的任职日期,使用了`Datetime`类型。 主键约束使用`PK_HeadMaster`名称进行命名,外键约束使用`FK_HeadMaster_S_ID`进行命名,对应`S_ID`列的外键关系。约束必须引用`School`表的`S_ID`列。 以上SQL语句创建了一个校长信息表`HeadMaster`,其中主键为`HeadID`列,`S_ID`列为`School`表的外键。 创建学校信息表`School`的SQL语句如下: ``` CREATE TABLE School ( S_ID CHAR(4) NOT NULL, S_Name VARCHAR(20) NOT NULL, s_add CHAR(20), CONSTRAINT PK_School PRIMARY KEY (S_ID) ); ``` 其中,`S_ID`、`S_Name`、`s_add`分别是学校信息表`School`的列名,对应的中文列名分别是学校编号、学校名称、学校地址。数据类型和长度分别如题所述。 主键约束使用`PK_School`名称进行命名。 以上SQL语句创建了一个学校信息表`School`,其中主键为`S_ID`列。 创建教师类型表`TeacherType`的SQL语句如下: ``` CREATE TABLE TeacherType ( TypeID CHAR(4) NOT NULL, TypeName CHAR(20) NOT NULL, CONSTRAINT PK_TeacherType PRIMARY KEY (TypeID) ); ``` 其中,`TypeID`、`TypeName`分别是教师类型表`TeacherType`的列名,对应的中文列名分别是类型编号、类型名称。数据类型和长度分别如题所述。 主键约束使用`PK_TeacherType`名称进行命名。 以上SQL语句创建了一个教师类型表`TeacherType`,其中主键为`TypeID`列。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值