E | Extreme Discrete Summation |
Given set S what is the value of the right hand side of thefollowing assignment? In other words
what is the value of A.
For example if S={1.2, 3.6, 4.1}then the possible values for variable is 1.2, 3.6 or 4.1.The same is true for variables , , , ,,,. Here means the nearestsmaller integer value of x (floor function). For example , , .
Input
The input file contains100 sets of inputs. The description of each set is given below:The input for each set is contained in a single line. Thisline starts with an integer N(0<N<101) whichdenotes how many numbers are in the set S. This integer is followed by Nnon-negative floating-point numbers in the same line. To make things easy withfloating-point numbers and to avoid precision problems these numbers have onlya single digit after the decimal point. Also the values of any of these numbersare not greater than 1000.
Input is terminated by line containing a single zero.
Output
For each set of inputproduce one line of output. This line contains an integer which denotes thevalue of A.
SampleInput Output for Sample Input
1 11.4 | 3 |
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
#define ll long long
const int maxn = 810;
ll dp[10][80];
int N;
vector<int> v;
void initial(){
for(int j = 0;j < 10;j++){
for(int k = 0;k < 80;k++){
dp[j][k] = -1;
}
}
v.clear();
}
void readcase(){
double t;
for(int i = 0;i < N;i++){
scanf("%lf" , &t);
int tem = int(t*10+0.0001);
//cout << tem%10 << ":" << t << " ";
//for(int j = 0;j < 8;j++){
v.push_back(tem%10);
//}
}
//cout << endl;
}
ll DP(int remain , int from){
if(remain == 0) return from/10;
if(dp[remain][from] != -1) return dp[remain][from];
ll ans = 0;
for(int i = 0;i < N;i++){
ans += DP(remain-1 , from+v[i]);
}
return dp[remain][from] = ans;
}
int main(){
//freopen("in" , "r" ,stdin);
while(cin >> N && N){
initial();
readcase();
printf("%lld\n" , DP(8 , 0));
}
return 0;
}