https://www.luogu.org/problem/P1149
#include <iostream> #include <string> #include <string.h> #include <stdio.h>
using namespace std; char array[10]={6,2,5,5,4,5,6,3,7,6}; int dst[24] = {0};
char str[8]={0};
int calc(int n) { memset(str, 0, 8); sprintf(str, "%d", n); int len=strlen(str); int iRet = 0; for (int i = 0; i < len; i++) { iRet += array[str[i]-'0']; } return iRet; }
int main(void) { for(int i=0;i <= 999; i++) { int i1 = calc(i); if (i1>16) { continue; } for(int j=0;j<=999;j++) { int j1 = calc(j); if (j1>16 || i1+j1 > 18) { continue; } int k=i+j; int k1=calc(k); int iUse=i1+j1+k1; if (iUse <= 20) { dst[iUse]++; } } } int n; cin>>n;
if(n<13) { cout <<0<<endl; } else { n-=4; cout <<dst[n]<<endl; } return 0; }
简化版本
#include <iostream> using namespace std; int dst[25] = {0}; int main(void) { dst[13] = 1; dst[14] = 2; dst[15] = 8; dst[16] = 9; dst[17] = 6; dst[18] = 9; dst[19] = 29; dst[20] = 39; dst[21] = 38; dst[22] = 65; dst[23] = 88; dst[24] = 128; int n; cin>>n; cout << dst[n] << endl; }
