Problem 2086 Restaurant ordering accept:349 submit:1106
Time limit:1000 mSec Memory limit:32768 KB Problem Description
Jack likes to eat at the school restaurant recently, it's good and clean and cheap.
In the school dining room, there is a soup, B type rice, c noodles, D meat, e vegetarian.
In order to ensure the meal collocation, Jack every meal will point 1~2 sample meat, 1~2 sample vegetarian dish (do not repeat). At the same time, when Jack is in a good mood, he will order the same meal, and then with a soup. When you are in a bad mood, you only eat one kind of noodles.
Because the economy is limited, Jack's price for each order is between Min~max. Jack wants to know how many different ordering options are in total. Input
The first row of the input data contains an integer t that represents the number of groups of test data, for each set of test data:
First act integer a,b,c,d,e (0<a,b,c,d,e<=10)
The second act A is a whole number greater than 0, indicating the price of a soup
Third act b a whole number greater than 0, indicating the price of Rice for B
Act c a whole number greater than 0, representing the price of the C noodle
Act d is a whole number greater than 0, which represents the price of D-type meat
Behavior e a whole number greater than 0, indicating the price of E vegetarian
Seventh Act Two integer min max, indicating the price range for each order the output for each set of test data, a row, contains an integer that represents the number of points in the menu. Sample Input 2 2 2 MB 8 Sample Output 3 Source Fuzhou University nineth session of the program Design competition
The idea of problem solving: Violent enumeration
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath > #include <algorithm> #include <stack> #include <queue> #include <climits> #include <
functional> #include <vector> #include <map> #include <set> using namespace std;
#define LL Long const int inf=0x3f3f3f3f;
int main () {int soup[10],rice[10],noodle[10],meat[10],veg[10];
int mi,ma;
int a,b,c,d,e;
int t;
scanf ("%d", &t);
while (t--) {int ans=0;
scanf ("%d%d%d%d%d", &a,&b,&c,&d,&e);
for (int i=0; i<a; i++) scanf ("%d", &soup[i]);
for (int i=0; i<b; i++) scanf ("%d", &rice[i]);
for (int i=0; i<c; i++) scanf ("%d", &noodle[i]);
for (int i=0; i<d; i++) scanf ("%d", &meat[i]);
for (int i=0; i<e; i++) scanf ("%d", &veg[i]);
scanf ("%d%d", &mi,&ma);
Sort (soup,soup+a); Sort (rice,rice+b);
Sort (noodle,noodle+c);
Sort (meat, meat+d);
Sort (veg,veg+e);
int sum;
for (int i=0; i<a; i++) for (int j=0; j<b; j + +) for (int r=0; r<d; r++) for (int y=r+1; y<d; y++) for (int w=0; w<e; w++) for (int h=w+ 1; h<e;
h++) {sum=soup[i]+rice[j]+meat[r]+meat[y]+veg[w]+veg[h];
if (Sum>=mi&&sum<=ma) ans++; }//a soup a meal two vegetarian for (int i=0; i<a; i++) for (int j=0; j<b; j + +) for (int r=0; r<d; r
+ +) for (int w=0; w<e; w++) for (int h=w+1; h<e; h++)
{Sum=soup[i]+rice[j]+meat[r]+veg[w]+veg[h];
if (Sum>=mi&&sum<=ma) ans++; }//a soup and a meat dish. for (int i=0; i<a; i++) for (int j=0; j<b; j + +) fo
R (int r=0; r<d; r++) for (int y=r+1; y<d; y++) for (int w=0; w<e; w++)
{SUM=SOUP[I]+RICE[J]+MEAT[R]+MEAT[Y]+VEG[W];
if (Sum>=mi&&sum<=ma) ans++; }//a soup Two meat a vegetarian for (int i=0; i<a; i++) for (int j=0; j<b; j + +) for (int r=0; r<d; r + +) for (int w=0; w<e; w++) {sum=soup[i]+rice[j]+meat[r
]+VEG[W];
if (Sum>=mi&&sum<=ma) ans++; }//a dish of soup a vegetarian for (int i=0; i<c; i++) for (int r=0; r<d; r++) for (int y=r+1; y<d; y++) for (int w=0; w<e; w++) for (int h=w+1; h<e; h++) {Sum=noodle[i]+meat[r]+meat[y]+veg[w]+veg[h];
if (Sum>=mi&&sum<=ma) ans++; }//Side two vegetarian for (int i=0; i<c; i++) for (int r=0; r<d; r++) for (int w=0; w<e; w++ for (int h=w+1; h<e; h++) {sum=noodle[i]+meat[r]+veg[
W]+VEG[H];
if (Sum>=mi&&sum<=ma) ans++; }//side of a meat two for (int i=0; i<c; i++) for (int r=0; r<d; r++) for (int y=r+1; y<d; y + +) for (int w=0; w<e; w++) {sum=noodle[i]+meat[r]+meat
[Y]+veg[w];
if (Sum>=mi&&sum<=ma) ans++; }//Side two vegetarian for (int i=0; i<c; i++) for (int r=0; r<d; r++) for (int w=0; w<e; w++) {int sum=noodle[i]+meat[r]+veg[w];
if (Sum>=mi&&sum<=ma) ans++;
}//one side of a meat and a vegetarian printf ("%d\n", ans);
return 0; }