Created
July 7, 2014 09:35
-
-
Save kdxu/ed63158b262cab200144 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sstream> | |
#include <string> | |
#include <cmath> | |
#include <cstdio> | |
#include <vector> | |
#include <map> | |
#include <set> | |
#include <queue> | |
#include <deque> | |
#include <algorithm> | |
#include <functional> | |
#include <numeric> | |
using namespace std; | |
int main(){ | |
int N; | |
int t[200]; | |
int ans1[1000000],ans2[1000000]; | |
for(int i=0;i<200;i++) t[i] = i*(i+1)*(i+2)/6; | |
ans1[0] = ans2[0] = 0; | |
for(int i=1;i<1000000;i++){ | |
ans1[i] = ans2[i] = i; | |
for(int j=0;t[j]<=i;j++){ | |
ans1[i] = min(ans1[i], ans1[i-t[j]]+1); | |
if(t[j]%2==1) ans2[i] = min(ans2[i], ans2[i-t[j]]+1); | |
} | |
} | |
while(1){ | |
cin >> N; | |
if(!N) break; | |
cout << ans1[N] << " " << ans2[N] << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment