uva 11485 Extreme Discrete Summation(DP)

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
4 537.0 365.1 870.2 841.7
2 216.5 4.8
0

3
101672
1196



#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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值