AtCoder Beginner Contest 167 C : Skill Up

题目

C - Skill Up


Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 300300 points

Problem

Takahashi, who is a novice in competitive programming, wants to learn MM algorithms. Initially, his understanding level of each of the MM algorithms is 00.

Takahashi is visiting a bookstore, where he finds NN books on algorithms. The ii-th book (1≤i≤N1≤i≤N) is sold for CiCi yen (the currency of Japan). If he buys and reads it, his understanding level of the jj-th algorithm will increase by Ai,jAi,j for each jj (1≤j≤M1≤j≤M). There is no other way to increase the understanding levels of the algorithms.

Takahashi's objective is to make his understanding levels of all the MM algorithms XX or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Constraints

  • All values in input are integers.
  • 1≤N,M≤121≤N,M≤12
  • 1≤X≤1051≤X≤105
  • 1≤Ci≤1051≤Ci≤105
  • 0≤Ai,j≤1050≤Ai,j≤105

Input

Input is given from Standard Input in the following format:

NN MM XX
C1C1 A1,1A1,1 A1,2A1,2 ⋯⋯ A1,MA1,M
C2C2 A2,1A2,1 A2,2A2,2 ⋯⋯ A2,MA2,M
⋮⋮
CNCN AN,1AN,1 AN,2AN,2 ⋯⋯ AN,MAN,M

Output

If the objective is not achievable, print -1; otherwise, print the minimum amount of money needed to achieve it.


Sample Input 1 Copy

Copy

3 3 10
60 2 2 4
70 8 7 9
50 2 3 9

Sample Output 1 Copy

Copy

120

Buying the second and third books makes his understanding levels of all the algorithms 1010 or higher, at the minimum cost possible.


Sample Input 2 Copy

Copy

3 3 10
100 3 1 4
100 1 5 9
100 2 6 5

Sample Output 2 Copy

Copy

-1

Buying all the books is still not enough to make his understanding levels of all the algorithms 1010 or higher.


Sample Input 3 Copy

Copy

8 5 22
100 3 7 5 3 1
164 4 5 2 7 8
334 7 2 7 2 9
234 4 7 2 8 2
541 5 4 3 3 6
235 4 8 6 9 7
394 3 6 1 6 2
872 8 4 3 7 2

Sample Output 3 Copy

Copy

1067

思路:因为数据较小,采用状压二进制暴力枚举对[1,1<<n)的每种情况进行枚举,1代表选择这本书,0代表不选择这本书,如果满足条件更新答案求最小值

code:

#include<iostream>
#include<cstring>
#include<cstdio> 
#define INF 0x3f3f3f3f

using namespace std;

const int N=20;
int c[N];
int n,m,x;
int a[N][N];
int ans=INF;
int main()
{
	cin>>n>>m>>x;
	for(int i=1;i<=n;i++){
		cin>>c[i];
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	for(int i=1;i<(1<<n);i++){
		int sum=0;//记录每种状态所花的钱 
		int res[N];//记录每种算法掌握程度 
		memset(res,0,sizeof(res));
		for(int j=0;j<n;j++){
			if(i&(1<<j)){//如果选择j+1本书 
				for(int k=1;k<=m;k++){
					res[k]+=a[j+1][k];
				}
				sum+=c[j+1];
			}
		}
		bool flag=0;
		for(int j=1;j<=m;j++){
			if(res[j]<x){
				flag=1;
				break;
			}
		}
		if(!flag) ans=min(sum,ans);
	}
	if(ans==INF) puts("-1");
	else cout<<ans<<endl;	
	return 0;
}
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值