nbut 1475
2013-07-20 11:00
267 查看
记忆化搜索的数位DP;
#include<iostream> #include<cstdio> #include<cstring> using namespace std; struct Calc{ int dp[11]; int digit[11]; int sum[11]; Calc(){memset(dp,-1,sizeof(dp));}; __int64 dfs(int pos, int pre, int have, int doing) { if(pos==-1) return have; if(!doing && dp[pos]!=-1){ if(pre==1) return pow(10,(double)pos+1)+dp[pos]; else return dp[pos]; } int end = doing?digit[pos]:9; __int64 ans = 0; if(pre == 1 && doing ) {ans+=sum[pos]+1;have=0;} for(int i=0; i<=end; i++) { int nhave = have; if(i == 1) nhave++; ans+=dfs(pos-1,i,nhave,doing&&(i==end)); } if(!doing) dp[pos]=ans; return ans; } __int64 calc(int x){ int i=0; int k=1; while(x) { digit[i] = x%10; sum[i] = digit[i]*k; if(i>0) sum[i] += sum[i-1]; i++; k*=10; x/=10; } return dfs(i-1,0,0,1); } }F; int main() { int n;while(~scanf("%d",&n)){ printf("%I64d\n",F.calc(n)); } return 0; }
相关文章推荐
- 数位dp 入门 nbut 1475
- django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not
- 解决Autowired required a single bean, but 2 were found问题
- 解决Autowired required a single bean, but 2 were found问题
- maven报错 the goal you specified requires a project to execute but there is no POM in this direct...
- 【嗨兴科技】Android Studio 3 报错:Device supports x86, but APK only supports armeabi-v7a解决方案之一
- hive启动出错:Found class jline.Terminal, but interface was expected
- The web application [test] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregist
- java.lang.IllegalStateException:The content of the adapter has changed but ListView did not receiv问题
- The goal you specified requires a project to execute but there is no POM in this directory 错误
- I asked for all things, that I might enjoy life but I was given life, that I might enjoy all things.
- Some words are similar but different in Software
- Tree View works through VWD but not via local host or from a remote browser. /Server Error in '/' Application.
- Use SqlDataAdapter to update database, but SqlCommandBuilder required
- delete all files but do not delete any directory
- done! but with errors on page
- FZU 1171 Hard to Believe, but True!
- 【ERROR】eclipse is running in a JRE,but a JDK is required
- variable 'std:ofstream' has initializer but incomplete type
- m2eclipse: Eclipse is running in a JRE, but a JDK is required