AtCoder Beginner Contest 080 C - Shopping Street【暴力枚举】
2017-12-08 16:49
531 查看
C - Shopping Street
Time limit : 2sec / Memory limit : 256MBScore : 300 points
Problem Statement
Joisino is planning to open a shop in a shopping street.Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods.
There are already N stores in the street, numbered 1 through N.
You are given information of the business hours of those shops, Fi,j,k. If Fi,j,k=1, Shop i is open during Period k on Day j (this notation is explained below); if Fi,j,k=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2.
Let ci be the number of periods during which both Shop i and Joisino’s shop are open. Then, the profit of Joisino’s shop will be P1,c1+P2,c2+…+PN,cN.
Find the maximum possible profit of Joisino’s shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.
Constraints
1≤N≤1000≤Fi,j,k≤1
For every integer i such that 1≤i≤N, there exists at least one pair (j,k) such that Fi,j,k=1.
−107≤Pi,j≤107
All input values are integers.
Input
Input is given from Standard Input in the following format:N
F1,1,1 F1,1,2 … F1,5,1 F1,5,2
:
FN,1,1 FN,1,2 … FN,5,1 FN,5,2
P1,0 … P1,10
:
PN,0 … PN,10
Output
Print the maximum possible profit of Joisino’s shop.Sample Input 1
11 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2
Sample Output 1
8If her shop is open only during the periods when Shop 1 is opened, the profit will be 8, which is the maximum possible profit.
Sample Input 2
21 1 1 1 1 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1
Sample Output 2
-2Note that a shop must be open during at least one period, and the profit may be negative.
Sample Input 3
31 1 1 1 1 1 0 0 1 1
0 1 0 1 1 1 1 0 1 0
1 0 1 1 0 1 0 1 0 1
-8 6 -2 -8 -8 4 8 7 -6 2 2
-9 2 0 1 7 -5 0 -2 -6 5 5
6 -6 7 -9 6 -5 8 0 -9 -7 -7
Sample Output 3
23题意: 五个工作日,分为上午下午两个时期,一共十个时期,依次排列,第i天第j个时期是否开门取决于 F[i][j],1表示开,0表示不开,然后给你第i天开门个数的收益,记为P[i][j],当j为0时表示都不开,当然题目要求最少开一个门,求最大收益
分析: 我们可以利用二进制来进行暴力枚举每个状态,从而取个最大收益
参考代码
#include<bits/stdc++.h> using namespace std; const int N = 1e5 + 10, INF = 0x3f3f3f3f ; int f [15]; int p [15]; int temp ; int main(){ ios_base::sync_with_stdio(0); int n;cin>>n; for(int i = 0;i < n;i++) { for(int j = 0;j < 10;j++) { cin>>f[i][j]; } } for(int i = 0;i < n;i++) { for(int j = 0;j <= 10;j++) { cin>>p[i][j]; } } ll res = -INF; for(int i = 1;i < (1<<10);i++) { memset(temp,0,sizeof temp); for(int j = 0;j < n;j++) { for(int k = 0;k < 10;k++) { if(f[j][k] && ((1<<k)&i)) { temp[j]++; } } } ll t = 0; for(int j = 0;j < n;j++) { t += p[j][temp[j]]; } res = max(res,t); } cout<<res<<endl; return 0; }
如有错误或遗漏,请私聊下UP,thx
相关文章推荐
- C - Shopping Street(AtCoder Beginner Contest 080)
- AtCoder Beginner Contest 088 C Takahashi's Information 【思维枚举】
- AtCoder Beginner Contest 085 C - Otoshidama【暴力】
- AtCoder Beginner Contest 069【A,水,B,水,C,数学,D,暴力】
- AtCoder Beginner Contest 067 B - Snake Toy
- AtCoder Beginner Contest 087 D - People on a Line 并查集(区间和问题)
- AtCoder Beginner Contest 091 D - Two Sequences
- AtCoder Beginner Contest 092 D - Grid Components
- 【AtCoder Beginner Contest 074 C】Sugar Water
- AtCoder Beginner Contest 084 C - Special Trains(思路)
- AtCoder Beginner Contest 085 C Otoshidama(计算机整数乘法问题+方程求解)
- AtCoder Beginner Contest 067 C - Splitting Pile
- AtCoder Beginner Contest 087 D - People on a Line 并查集(区间和问题)
- AtCoder Beginner Contest 051 ABCD题
- 【AtCoder Beginner Contest 074 B】Collecting Balls (Easy Version)
- AtCoder Beginner Contest 084 C - Special Trains(思路)
- AtCoder Beginner Contest 067 D - Fennec VS. Snuke
- AtCoder Beginner Contest 087 D - People on a Line 并查集(区间和问题)
- AtCoder Beginner Contest 069
- AtCoder Beginner Contest 054